Introduction
Natural Numbers are non-negative whole numbers starting from 1, i.e. a set of positive integers {1,2,3,....................... so on}. Natural numbers are used for counting or ordering {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11…}
To print all the natural numbers from 1 to n, we will use loop statements of C language to carry out the program.
Code
This program allows the user to enter an integer. Using For loop, we will print the list of natural numbers from 1 to the entered value.
Method 1: Using For Loop
In this method, we will take a for loop and iterate a variable i from 1 to the user entered limit n by incrementing by 1 through every loop. Then, inside the loop we will print each number(i) up to n.
#include<stdio.h>
void main() {
int i,n=14;
for(i=1;i<=n;i++){
printf("%d ", i);
}
printf("\n");
}
Output
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Also see, Short int in C Programming