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:
Tags
c++