Dremendo Tag Line

Input number and print factors using for loop in C

for Loop - Question 9

In this question, we will see how to input a number and print its factors in C programming using for loop. To know more about for loop click on the for loop lesson.

Q9) Write a program in C to input a number and print its factors using for loop.

Program

#include <stdio.h>
#include <conio.h>

int main()
{
    int i,n;

    printf("Enter a number ");
    scanf("%d",&n);
    printf("Factors are\n");
    for(i=1; i<=n; i=i+1)
    {
        if(n%i==0)
        {
            printf("%d\n",i);
        }
    }
    return 0;
}

Output

Enter a number 12
Factors are
1
2
3
4
6
12
video-poster