Natural number

Natural numbers are numbers that are common and clearly in nature. As such, it is a whole, nonnegative number.

Logic

To print the first N natural number we only have to run one single loop from 1 to N.

After taking input (num) from user start one loop from 1 to num, and then inside the loop simply print the current variable “i”.

See also: Calculate sum of first N natural numbers

Program

#include <iostream>

using namespace std;

int main() {

    int i, num;

    // Take number from user
    cout << "Enter any number : ";
    cin >> num;

    cout << endl << "Natural numbers from 1 to " << num << endl;
    for(i = 1; i <= num; i++) {

        cout << i << " ";
    }

    return 0;
}

Output

Enter any number : 10
Natural numbers from 1 to 10 1 2 3 4 5 6 7 8 9 10