Hey coders, today you will learn **how to print all natural numbers from 1 to N using a While loop**.

As you already know, natural numbers are all positive integers ranging from 1 to infinity. They are also known as counting numbers because they are used to count different objects.

Don’t forget that natural numbers do not include zero or negative integers.

In this tutorial, we will learn to write a C program which prompts the user to enter the upper limit or value of N, then this program will automatically print all natural numbers from 1 to N. This can be done using many approaches, but for this tutorial, we will go with the While loop approach.

So, without further ado, let’s begin this tutorial.

**C Program to Print all Natural Numbers from 1 to N Using While Loop**

**C Program**

// C Program to Print ALl Natural Numbers from 1 to N Using While Loop #include <stdio.h> int main() { int i = 1, N; // Asking for input printf("Enter the value of N: "); scanf("%d", &N); // Printing all natural numbers from 1 to N while (i <= N) { printf("%d\n", i); i++; } return 0; }

**Output 1**

```
Enter the value of N: 7
1
2
3
4
5
6
7
```

**Output 2**

```
Enter the value of N: 15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
```

**Output 3**

```
Enter the value of N: 125
1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
```

**How does this Program Work?**

int i = 1, N;

In the first line of the program, we have declared two variables `i`

and `N`

. We have assigned a value of 1 to `i`

variable.

// Asking for input printf("Enter the value of N: "); scanf("%d", &N);

Then, we take input from the user using the `scanf()`

function. The `scanf()`

function is used to read input from the input. Here, the user is asked to enter the upper limit up to which the user wants to print the numbers. The entered number gets stored in the `N`

variable.

// Printing all natural numbers from 1 to N while (i <= N) { printf("%d\n", i); i++; }

After that, we defined a while loop which checks whether the value of `i`

is less than or equal to `N`

or not, if it is less than `N`

, then this loop is executed, and it prints the value of `i`

and then increments the value of i. This loop keeps on iterating until the value of `i`

is greater than the value of `N`

.

**Conclusion**

I hope you all understand how to print all natural numbers from 1 to N using a While loop in the C programming language.

You can also use the same logic to print the natural numbers in the for loop and do-while loop approach.