find all factors of a number with C
If a number is exactly divisible by a number, Then the number is a factor of the num
suppose 7 is exactly divisible by 1 & 7, Then the number is a factor of num
suppose 15 is exactly divisible by 1,3 & 5, Then the number is a Not factor of num
#include <stdio.h>
int main()
{
int i, num;
printf("Enter number to find its factor: ");
scanf("%d", &num);
printf("All factors of %d are: \n", num);
for (i = 1; i <= num; i++)
{
if (num % i == 0)
{
printf("%d, ", i);
}
}
return 0;
}
output:
Enter number to find its factor : 15
All factors of 15 are : 1 3 5 15
0 Comments