Thursday 28 June 2012

c++ program that display following pattern.

for n=5;
1
2 3
4 5 6
7 8 9 10






#include <iostream>
using namespace std;

int main()
{
int i,j,k,n;
n=1;



//input from user
cout<<"Enter a number ";
cin>>k;

for(i=1;i<=k;i++)
{
for(j=1;j<=i;j++)
{
cout<<n<<" ";
n=n+1;
}
cout<<"\n";
}
return 0;
}




No comments:

Post a Comment