Learn about Program to find factors of a number in C using for loop in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
Program to find factors of a number in C using for loop
The below C code takes a number as input and finds the factors of the given number using a For loop.
Source code:
#include<stdio.h>
int main()
{
int num;
printf("Enter number: ");
scanf("%d",&num);
printf("Factors of %d are:\n", num);
for(int i=1; i<=num/2; i++)
{
if(num%i==0)
printf("%d\t", i);
}
return 0;
}
Output:
Enter number: 10
Factors of 10 are:
1 2 5
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
C Program to Find Reverse of a Number using for loop
C Program to Find Reverse of a Number using the do-while loop