In this post, we will learn how to print natural numbers in reverse from N to 1 using C Programming language.
This program asks the user to enter the end value, then it will print the natural numbers in reversed order using the following approaches:
- Reverse Using Standard Method
- Reverse numbers In a Range
- Reverse First 10 Natural Numbers
So, without further ado, let’s begin this tutorial.
C Program to Print Natural Numbers in Reverse From N to 1
// C Program to Print Natural Numbers in Reverse From N to 1 #include <stdio.h> int main(){ int i, num; // Asking for input printf("Enter the last number: "); scanf("%d", &num); printf("Natural numbers in reversed order from %d to 1: \n", num); for (i = num; i >= 1; i--){ printf("%d\n", i); } return 0; }
Output
Enter the last number: 15
Natural numbers in reversed order from 15 to 1:
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
How Does This Program Work ?
int i, num;
In this program, we have declared two int data type variables named i and num.
// Asking for input printf("Enter the last number: "); scanf("%d", &num);
Then, the user is asked to enter the last number.
printf("Natural numbers in reversed order from %d to 1: \n", num); for (i = num; i >= 1; i--){ printf("%d\n", i); }
We used for loop to print the natural numbers in reversed order.
C Program to Print Natural Number in Reverse in Given Range
// C Program to Print Natural Numbers in Reverse in Given Range #include <stdio.h> int main(){ int i, start, last; // Asking for input printf("Enter the starting value: "); scanf("%d", &start); printf("Enter the ending value: "); scanf("%d", &last); // printf("Reverse natural numbers from %d to %d: \n", start, end); for (i = start; i >= last; i--){ printf("%d\n", i); } return 0; }
Output
Enter the starting value: 7
Enter the ending value: 2
7
6
5
4
3
2
C Program to Print First 10 Natural Numbers in Reverse Order
// C Program to Print First 10 Natural Numbers in Reverse #include <stdio.h> int main(){ int i; printf("The first 10 natural numbers in reverse: \n"); for (i = 10; i >= 1; i--){ printf("%d\n", i); } return 0; }
Output
The first 10 natural numbers in reverse:
10
9
8
7
6
5
4
3
2
1
Conclusion
I hope after going through this post, you understand how to print natural numbers in reverse order using C Programming language.
If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to assist you.
Also Read:
- C Program to Find Area of Rhombus
- C Program to Concatenate Two Strings
- C Program to Find Absolute Value of a Number
- C Program to Find Circumference of Circle
- C Program to Find Sum and Average of 3 Numbers