# C program to find factors of a number using while loop and for loop

In this article, you will learn how to find factors of a number using for loop and while loop in the c programming language.

### Examples

**Input: 60**

**The factors of the 60 are: 1 2 3 4 5 6 10 12 15 20 30 60**

**Input: 70**

**The factors of the 70 are: 1 2 5 7 10 14 35 70**

## What are the factors of a number?

The factors of a number are defined as numbers that divided the original number without leaving any remainder **(left reminder = 0)**.

You should have knowledge of the following topics in c programming to understand these programs:

- C

function**main()** - C

loop statement**for** - C

loop statement**while** - C

statement**if** - C

function**printf()**

### 1. C program to find factors of a number using while loop

```
// C program to find factors of a number using while loop
#include <stdio.h>
int main() {
int x, i = 1;
printf("-----Enter the positive integer number-----\n");
scanf("%d", &x);
printf("\nThe factors of the %d are: ", x);
while (i <= x) {
if (x % i == 0) {
printf("%d ", i);
}
++i;
}
printf("\n");
return 0;
}
```

### Output

`-----Enter the positive integer number-----`

90

`The factors of the 90 are: 1 2 3 5 6 9 10 15 18 30 45 90`

### 2. C program to find factors of a number using for loop

```
// C program to find factors of a number using for loop
#include <stdio.h>
int main() {
int x, i;
printf("-----Enter the positive integer number-----\n");
scanf("%d", &x);
printf("\nThe factors of the %d are: ", x);
for (i = 1; i <= x; ++i) {
if (x % i == 0) {
printf("%d ", i);
}
}
printf("\n");
return 0;
}
```

### Output

`-----Enter the positive integer number-----`

90

`The factors of the 90 are: 1 2 3 5 6 9 10 15 18 30 45 90`

### Explanation

In these given programs, we have taken input

a random number then applied the **90**

loop and makes a calculation on this random number.**while**

With It self reminder zero to find the possible factors of this random number.

The same calculation applied to the second program with

loop.**for**