#include<iostream>
#include<conio.h>
using namespace std;
main()
{
int x,i,j; //variable declaration
cout<<"Enter number of rows: "; //asking input from user
cin>>x; //taking input
for(i=x;i>=1;i--) //tells first value in a row
{
for(j=i;j>=1;j--) //set values in decending order from first value till 1
{
cout<<j; // printing pattern
}
cout<<"\n"; //jumping to next line
}
getch();
}
Output :
54321
4321
321
21
1
#include<conio.h>
using namespace std;
main()
{
int x,i,j; //variable declaration
cout<<"Enter number of rows: "; //asking input from user
cin>>x; //taking input
for(i=x;i>=1;i--) //tells first value in a row
{
for(j=i;j>=1;j--) //set values in decending order from first value till 1
{
cout<<j; // printing pattern
}
cout<<"\n"; //jumping to next line
}
getch();
}
Output :
54321
4321
321
21
1
Also See TOWER OF HANOI CLICK HERE