C++ Program to print 1 to N in reverse
To get the required output for this program, iterate the loop from n to 1, that is change the normal conditions of the loop.
Code
#include <iostream>
using namespace std;
int main() {
cout<<"Enter a number "<<endl; //Requesting a Number
int n;
cin>>n;
for(int i=n;i>0;i--){ //Loop to print to print 1 to N in reverse
cout<<i<<endl;
}
return 0;
}
Input
7
Output
Enter a number
7
6
5
4
3
2
1
0 Comments