Simple example : Using loop

#include <iostream.h>
#include <conio.h>
//To display 1,2,3,……….k
void main( )
{
int n, k;
clrscr();
cout<<”Enter a number \n”;
cin>>k;
cout<<”The sequence is \n”
for( n = 1; n<=k; n++)
cout<<n<<”\n”
getch();
}
Output :
Enter a number
10
The sequence is
1
2
3
4
5
6
7
8
9
10

0 comments: