C++ Program to Print Natural Numbers

C++ Program to Print Natural Numbers

How to Print Natural Numbers from 1 to n by C++? In C++ we can print n consecutive Natural Numbers by using Loops. Here in this program we used "while loop" to get our desired output.

Printing Natural Numbers by C++ :



#include <iostream>
using namespace std;

int main() 
{
    int n, i=1;
    
    cout << "Please Enter the range : ";
    cin >> n;
    cout << "The List of Natural Numbers from 1 to " << n << " are : ";

    while ( i <= n )
    {
        cout << i << " ";
        i++;
    }

    return 0;
}


Output :