You are on page 1of 2

#include<iostream>

using namespace std;

int main( )

// input should be odd

int n=9; for(int r=1;r<=n;++r)

for (int sp=1;sp<=2*(n+2);++sp) //loop for constant spacing

cout<<" ";

for (int sp=n;sp>r;--sp)

cout<<" ";

for (int ast=1;ast<=r;++ast) //loop for pyramid asterics printing

cout<<" ";

cout<<" \n";

//middle part

//uper middle part

for (int r=1;r<=(n+3)/2;++r) //loop for upper middle part row

for(int sp=1; sp<=3*(r-1)+1; ++sp)

for(int ast=(n+1); ast>= 3*(r-1)+1;--ast)

// lower middle part

for(int r=1; r<= n/2-1 ; ++r)

for(int sP=3*(n+1)/2 ; sP>=r; - -sP) // loop for space


cout<< " ";

for(int ast=1; ast <= (3*n)/2 + r; ++ast) // loop for asterics

cout<<" ";

cout<<"\n";

// bottom part

for(int r=1; r<= (n+1)/2 ; ++r) //loop for

for (int sp=(2*n+7)/2 ; sp>=r; --sp)

cout<<" ";

for(int ast=n ; ast>2*(r-1) ; --ast)

cout<<" ";

for (int sp=1; sp<=10*(r-1)+2 ; ++sp)

cout<<" ";

for(int ast=n; ast> 2*(r-1);--ast)

cout<<" ";

cout<<"\n";

Explanation

I have discussed in comments during program coding

You might also like