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