/* c program to find the factors of a given number */
#include<stdio.h>
int main()
{
int n,i;
printf("enter n:");
scanf("%d",&n);
if(n<=0)
printf("invalid number to find the factors");
printf("\n");
for(i=1;i<=n; i++)
{
if(n%i==0) /* if 'i' divides n, its factor of n */
printf("%d\t ",i);
}
return(0);
}
Sample input and output:
enter n:8
1 2 4 8