C program to find all factors of a given number.
Hints:
- Factors of 6 are 1, 2, 3, 6
- Factors of 15 are 1, 3, 5, 15
- Factors of 17 are 1, 17
int main()
{
int i, number;
// Read a number from user
printf("Enter number to find its factor:");
scanf("%d", &number);
printf("Factors of %d are as under:\n", number);
/* Loop to find factors */
for(i=1; i<=number; i++)
{
if(number % i == 0)
{
printf("%d\n",i);
}
}
return 0;
}
Output of program
Enter number to find its factor:15
Factors of 15 are as under:
1
3
5
15