Program for half pyramid of numbers
Program for half pyramid of numbers
#include<iostream>
using namespace std;
int main()
{
int i,j,n,m=0;
cout<<"enter how many rows of pyramid you want";
cin>>n;
for(i=n;i>=1;--i)
{
for(j=1;j<=i;++j)
{
cout<<j<<" ";
}
cout<<endl;
}
return 0;
}
Output:
enter how many rows of pyramid you want6
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Program for inverted half pyramid of numbers
#include<iostream>
using namespace std;
int main()
{
int i,j,n,m=0;
cout<<"enter how many rows of pyramid you want";
cin>>n;
for(i=n;i>=1;--i)
{
for(j=1;j<=i;++j)
{
cout<<j<<" ";
}
cout<<endl;
}
return 0;
}
output:
enter how many rows of pyramid you want6
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Comments
Post a Comment