Write a C program to enter any number from user and print all factors of given number using for loop. How to find factors of any number in C programming. C program to display all factors of any number using loop.

Input number: 12

Output factors of 12: 1, 2, 3, 4, 6, 12

Happy coding ;)

**Example:**Input number: 12

Output factors of 12: 1, 2, 3, 4, 6, 12

### Required knowledge

Basic C programming, If else, For loop#### Factor of a number

A factor of any number is a whole number which exactly divides any number into a whole number without leaving any remainder. For example: 2 is a factor of 6 because 2 divides 6 exactly leaving no remainder.### Logic to find factors of any number

Finding factors of any number will be easy if you know how to check whether a number is exactly divisible by any number or not. Now what we need to do here is just iterate from 1 to n (where n is the number whose factor is to be found) and print all those numbers that are exactly divides n.### Program to find factors of any number

/** * C program to print all factors of any number */ #include <stdio.h> int main() { int i, num; /* Reads number whose factors is to be found */ printf("Enter any number to find its factor: "); scanf("%d", &num); printf("All factors of %d are: \n", num); /* Iterates from 1 to n */ for(i=1; i<=num; i++) { /* * If num is exactly divisible by i * Then i is a factor of num */ if(num%i==0) { printf("%d\n",i); } } return 0; }

Output

Enter any number to find its factors: 100

All factors of 100 are:

1

2

4

5

10

20

25

50

100

All factors of 100 are:

1

2

4

5

10

20

25

50

100

Happy coding ;)

### You may also like

- Loop programming exercises index.
- C program to find all Prime factors of a number.
- C program to find factorial of a number.
- C program to print all natural numbers from 1 to n.
- C program to print all even numbers from 1 to n.
- C program to print all odd numbers from 1 to n.
- C program to find reverse of any number.
- C program to check whether a number is Palindrome or not.
- C program to find power of any number using for loop.
- C program to check Prime numbers.
- C program to check Armstrong numbers.
- C program to check Strong numbers.
- C program to check Perfect numbers.

< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).