Display factors of a number
C Program to Display Factors of a Number.
Factor of any number is a whole number which exactly divides the number into a whole number without leaving any remainder. For example: 3 is a factor of 9 because 3 divides 9 exactly leaving no remainder.
For example, Factors of 30 are:
1 * 30 = 30
2 * 15 = 30
3 * 10 = 30
5 * 6 = 30
So, factors are: 1, 2, 3, 5, 6, 10, 15 and 30.
For example, Factors of 30 are:
1 * 30 = 30
2 * 15 = 30
3 * 10 = 30
5 * 6 = 30
So, factors are: 1, 2, 3, 5, 6, 10, 15 and 30.
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int num, i;
printf("Enter a positive integer\t:");
scanf("%d",&num);
printf("Factors of %d are: ", num);
for(i=1; i <= num; i++)
{
if(num%i == 0)
{
printf("%d, ",i);
}
}
getch();
}
Output
Enter a positive integer :84
Factors of 84 are: 1, 2, 3, 4, 6, 7, 12, 14, 21, 28, 42, 84,