Monday, September 10, 2018

Print Number Pyramid

/* Number pyramid
            1
           121
  12321
*/ 
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
int num,r,c; // To input number of lines
cout<<"Enter Number "; cin>>num;
for( r=1; r<=num; r++) {
for(int sp=1;sp<=num-r;sp++) // SPACES BEFORE NUMBER
  cout<<" ";
for( c=1 ; c<=r; c++)//inner loop 2
{
cout<<c; // will print NUMBER in a single line
}
for(int k=c-2;k>=1;k--)
{
cout<<k;
}
cout<<"\n"; // At end of inner loop next line will
// come in a new line
}
getch();
}

No comments:

Post a Comment