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