How to write a C Program to Print Natural Numbers in reverse order using For Loop and While Loop?.
C Program to Print Natural Numbers in reverse using For Loop
This program allows the user to enter any integer value. Using For loop, we will print the list of natural Numbers from user-entered value to 1.
/* C Program to Print Natural Numbers in reverse using For Loop */ #include<stdio.h> int main() { int Number, i; printf("\n Please Enter the Maximum Integer Value (Upper Limit) : "); scanf("%d", &Number); printf("\n List of Natural Numbers from %d to 1 are \n", Number); for(i = Number; i >= 1; i--) { printf(" %d \t", i); } return 0; }

For loop First Iteration: for(i = 5; 5 >= 1; 5–)
Printf statement will print i = 5
For Loop Second Iteration: for(i = 4; 4 >= 1; 4–)
Printf statement will print i = 4
It will go on until i reaches 0
C Program to return Natural Numbers in reverse using While Loop
This program to Print Natural Numbers in reverse order is the same as above. We just replaced the For Loop with While Loop.
/* C Program to Print Natural Numbers in reverse using While Loop */ #include<stdio.h> int main() { int Number, i; printf("\n Please Enter the Maximum Integer Value (Upper Limit) : "); scanf("%d", &Number); i = Number; printf("\n List of Natural Numbers from %d to 1 are \n", Number); while(i >= 1) { printf(" %d \t", i); i--; } return 0; }
Please Enter the Maximum Integer Value (Upper Limit) : 25
List of Natural Numbers from 25 to 1 are
25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
C Program to return Natural Numbers in reverse within a Range
Instead of simply printing natural numbers from n to 1, this program allows the user to enter both the Minimum and maximum value. Next, the C Programming compiler will display natural numbers from Maximum value to Minimum.
/* C Program to Print Natural Numbers in Reverse within a Range */ #include<stdio.h> int main() { int i, Starting_Value, End_Value; printf("\n Please Enter the Starting Value (Maximum Integer or Upper Limit) : "); scanf("%d", &Starting_Value); printf("\n Please Enter the End Value (Minimum Integer or Lower Limit) : "); scanf("%d", &End_Value); printf("\n List of Natural Numbers from %d to %d are \n", Starting_Value, End_Value); for(i = Starting_Value; i >= End_Value; i--) { printf(" %d \t", i); } return 0; }
Please Enter the Starting Value (Maximum Integer or Upper Limit) : 62
Please Enter the End Value (Minimum Integer or Lower Limit) : 2
List of Natural Numbers from 62 to 2 are
62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2