Factor of a number
C Program to find the factor of a number
#include<stdio.h>
int main()
{
int n, i;
printf("\nEnter the number to find the factors of : ");
scanf("%d",&n);
printf("\n\n\nFactors of %d are: \n", n);
for(i = 1; i <= n/2; i++)
{
if(n%i == 0)
printf("\t\t%d\n", i);
}
return 0;
}
output:
Enter the number to find the factors of : 128
Factors of 128 are:
1
2
4
8
16
32
64
int main()
{
int n, i;
printf("\nEnter the number to find the factors of : ");
scanf("%d",&n);
printf("\n\n\nFactors of %d are: \n", n);
for(i = 1; i <= n/2; i++)
{
if(n%i == 0)
printf("\t\t%d\n", i);
}
return 0;
}
output:
Enter the number to find the factors of : 128
Factors of 128 are:
1
2
4
8
16
32
64
Comments
Post a Comment