C Program To Find Factors Of A Number
C Program To Find Factors Of A Number
In this example, you will learn to Find Factors Of A Number
Example :
Enter Any Number To Find Factors 12
Factors Of The Given Number Are = 1, 2, 3, 4, 6, 12
How Program Works ??
- Input number from user. Store it in variable say number.
- Run a loop Example (i = 1; i <= Number; i++)
- To check factor if(number % i == 0) then i is a factor of num.
- If i is a factor of number then print i.
Logic ??
Factor of any number is a number which exactly divides the number into a whole number without any remainder.
Code For "Find Factors Of A Number".
/* Author --> HARSH PATEL */
#include <stdio.h>
int main()
{
int i, Number;
printf("\nEnter Any Number To Find Factors \n");
scanf("%d", &Number);
printf("\nFactors Of The Given Number Are = \n");
for (i = 1; i <= Number; i++)
{
if(Number%i == 0)
{
printf(" %d ", i);
}
}
return 0;
}
Enter Any Number To Find Factors
12
Factors Of The Given Number Are =
1 2 3 4 6 12
Enter Any Number To Find Factors
25
Factors Of The Given Number Are =
1 5 25
Enter Any Number To Find Factors
100
Factors Of The Given Number Are =
1 2 4 5 10 20 25 50 100
Enter Any Number To Find Factors
10
Factors Of The Given Number Are =
1 2 5 10
Enter Any Number To Find Factors
234
Factors Of The Given Number Are =
1 2 3 6 9 13 18 26 39 78 117 234
Enter Any Number To Find Factors
1
Factors Of The Given Number Are =
1
- Now Program End Without Any Error.
![🖥️](https://fonts.gstatic.com/s/e/notoemoji/14.0/1f5a5_fe0f/32.png)
![👨🎓](https://fonts.gstatic.com/s/e/notoemoji/14.0/1f468_200d_1f393/32.png)
![👩🎓](https://fonts.gstatic.com/s/e/notoemoji/14.0/1f469_200d_1f393/32.png)