Write a program in C++ to display n terms of natural number using while loop.

Write a program in C++ to display n terms of natural number using while loop.

Sample Output:

Input a number of terms: 7

The natural numbers upto 7th terms are:

1 2 3 4 5 6 7 


#include<iostream>

using namespace std;

int main()

{

int a=1;

cout<<"Input a number of terms: 7"<<endl;

cout<<"The natural numbers upto 7th terms are: "<<endl;

while(a<=7)

{

cout<<a++<<" ";

}

return 0;

}


Output:

Write a program in C++ to display n terms of natural number using while loop.

Post a Comment

Please do not enter any spam link in the comment box.

Previous Post Next Post