C++ code to print natural numbers

This program will print natural number from 1 to n. For example, if you have entered 10 then it will print natural numbers from 1 to 10.

#include
#include
void main()
{
int n,i;
clrscr();
cout<<"Enter the value of n:";
cin>>
cout<<"nThe series is:nn";
for(i=1;i<=n;i++)
{
cout<}
getch();
}

Output:

Enter the value of n: 8

The series is:
1 2 3 4 5 6 7 8

Add Comment