#include<iostream.h>
#include<iomanip.h>
void main()
{
int i,j,k,n,j2;
cout<<" Enter the height of pyramid : ?\b ";
cin>>n;
for(i=1;i<=n;i++)
{
for(k=1;k<=(n-i);k++)
cout<<setw(3)<<" ";
for(j=1;j<=i;j++)
cout<<setw(3)<<i+j-1;
for(j2=1;j2<=(i-1);j2++)
cout<<setw(3)<<2*i-j2-1;
cout<<endl;
}
}
Output:
Enter the height of pyramid : 7
1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5
6 7 8 9 10 11 10 9 8 7 6
7 8 9 10 11 12 13 12 11 10 9 8 7
Press any key to continue |