C Program to print the Factors of a given number
The following program displays the factors of a given number. For example, if the user enters 7, it displays 1 and 7.
since 1*7 =7, and 7*1=7.
We can also extend this program to check this number is a prime number or not by counting the number of factors. for example if the total number of factors is 2, then the given number is a prime number, otherwise, it is not a prime number.
Output:
Enter any positive integer: 24
Factors of 24 are:
1
2
3
4
6
8
12
24
——————————–
Process exited after 230.3 seconds with return value 0
Press any key to continue . . .
Factors of 24 are:
1
2
3
4
6
8
12
24
——————————–
Process exited after 230.3 seconds with return value 0
Press any key to continue . . .