c++ program that display following triangle pattern.
for n=3;
pattern:
1
2 3
4 5 6
#include <iostream>
using namespace std;
int main()
{
int i,j,k,x;
//input from user
cout<<"Enter a number ";
cin>>k;
x=1;
for(i=1;i<=k;i++)
{
for(j=1;j<=i;j++)
{
cout<<x<<" ";
x=x+1;
}
cout<<"\n";
}
return 0;
}
No comments:
Post a Comment