Drawing different shapes like triangles, diamonds, pyramids etc. is the very basics of programming and are very important to learn and understand. Let’s start how to draw a Reverse Pyramid shape in C++ programming code.
For other triangle, diamonds & Pyramid shapes see -> Patterns and Shapes in C++
We will make our program to draw following structure of reverse pyramid
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
Program:
#include <iostream>
using namespace std;
int main()
{
int rows,i,j,space;
cout<<"Enter number of rows: ";
cin>>rows;
for(i=rows;i>=1;--i)
{
for(space=0;space<rows-i;++space)
cout<<" ";
for(j=i;j<=2*i-1;++j)
cout<<"* ";
for(j=0;j<i-1;++j)
cout<<"* ";
cout<<endl;
}
return 0;
}