Reverse Printing Numbers using For Loop in C++


This is a C++ program that prompts the user to input a limit, and then prints all the natural numbers from the limit down to 1, inclusive. Here is a brief explanation of the program:

  • The program declares two integer variables: n and i, and initializes i to 1.
  • The program prompts the user to input the limit, and reads it from the standard input using the cin object.
  • The program enters a for loop that iterates n times, from n to 1 inclusive. In each iteration, the loop body is executed.
  • In the loop body, the program outputs the current value of n to the standard output using the cout object.
  • After the loop terminates, the program returns 0 to the operating system, indicating successful execution.

Source Code

#include<iostream>
using namespace std;
int main()
{
    int n,i=1;
    cout<<"\nEnter the limit:";
    cin>>n;
    for(n;n>=i;n--)
    {
        cout<<"\n"<<n;
    }
    return 0;
}
To download raw file Click Here

Output

Enter the limit:10
10
9
8
7
6
5
4
3
2
1

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples