C Programming Code Examples C > For Loops and While Loops Code Examples print all natural numbers from 1 to n print all natural numbers from 1 to n Write a C program to print all natural numbers from 1 to n using loop. C program to print first n natural numbers using loop. How to print natural numbers in a given range using loop. Logic to print natural numbers using for loop in C program. Logic to print natural numbers from 1 to n There are various ways to print n numbers. Input upper limit to print natural number from user. Store it in some variable say N. Run a for loop from 1 to N with 1 increment. The loop structure should be like for(j=1; j<=N; j++). At this point you might be thinking of various things such as. Why starting from 1? Because we need to print natural numbers from 1. Why going till N? Because we need to print natural numbers up to N. Why increment loop counter by 1? Because difference between two natural numbers is 1. Therefore if n is one natural number then next natural number is given by n+1. Inside the loop body print the value of j. You might think, why print value of j inside loop? Because we need to print natural numbers from 1 to N and from loop structure it is clear that j will iterate from 1 to N. So to print from 1 to N print the value of j. #include <stdio.h> int main() { int j, n; /* Input upper limit from user */ printf("Enter any number: "); scanf("%d", &n); printf("Natural numbers from 1 to %d : \n", n); /* * Start loop counter from 1 (j=1) and go till n (j<=n) * increment the loop count by 1 to get the next value. * For each repetition print the value of j. */ for(j=1; j<=n; j++) { printf("%d\n", j); } return 0; }