Definition
This program is used to find the total number of divisors (factors) of a given number.
A divisor is a number that divides another number exactly without leaving a remainder.
For example:
Divisors of 12 are: 1, 2, 3, 4, 6, 12
Total divisors = 6
The program uses a while loop to check all numbers from 1 to n and counts how many numbers divide n exactly.
Algorithm:
Step 1: Start
Step 2: Input n
Step 3: Set i = 1
Step 4: Set count = 0
Step 5: Check i <= n
Step 6: If n % i == 0, increment count by 1
Step 7: Increment i by 1
Step 8: Repeat Steps 5 to 7 until i > n
Step 9: Print count
Step 10: Stop.
Flowchart:
┌─────────┐
│ START │
└────┬────┘
│
▼
┌────────────────┐
│ Input n │
└───────┬────────┘
│
▼
┌─────────────────┐
│ i = 1 │
│ count = 0 │
└───────┬─────────┘
│
▼
┌───────┐
│i <= n?│
└──┬─┬──┘
Yes No
│ │
│ ▼
│ ┌──────────┐
│ │Print Count│
│ └────┬─────┘
│ │
│ ▼
│ ┌─────┐
│ │ END │
│ └─────┘
│
▼
┌───────────┐
│n%i == 0 ? │
└──┬────┬───┘
Yes No
│ │
▼ │
┌──────────────┐
│count=count+1 │
└──────┬───────┘
│
▼
┌─────────┐
│ i=i+1 │
└────┬────┘
│
└──────────► Back to i <= n
code:
n = int(input("Enter number: "))
i = 1
count = 0
while i <= n:
if n % i == 0:
count += 1
i += 1
print("Count =", count)
Example:
Input:
Enter number: 12
Output:
Count = 6
Top comments (0)