Question #286355

Program all natural number from 1 to n using while loop

Expert's answer

#include <iostream>
using namespace std;

int main() {
    int i, n;

    cin >> n;
    i = 1;

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

    return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS