Inverted Half Pyramid Pattern in C++

In this article, we are going to learn about how to print an inverted half Pyramid pattern in C++ language. First, we are going to print the inverted half Pyramid and then in the next program, we will print the full inverted Pyramid.

  1. How to print inverted half Pyramid using * in C++ language.
  2. How to print full inverted Pyramid using * in C++ language.
Desired Output for Size 5:

* * * * *
* * * *
* * *
* *
*

1. How to print inverted half Pyramid in C++


#include <iostream>
using namespace std;
int main()
{

  int num;

  cout<<"Please enter the number of rows: ";
  cin>>num;

  for(int i=num;i>=1;i--)
  {

    for(int j = i; j >= 1; j--)
    {
       cout<<"* ";
    }

    cout<<"\n";
  }

  return 0;
}

Output

Please enter the number of rows: 7
* * * * * * * 
* * * * * * 
* * * * * 
* * * * 
* * * 
* * 
* 

2. How to print full inverted Pyramid of * in C++ language.


Desired Output for Size 5:

* * * * *
* * * *
* * *
* *
*
#include <iostream>
using namespace std;
int main()
{
  int num, row, col;

  cout<<"Please enter the number of rows: ";
  cin>>num;

  for(row = num; row >= 1; row--)
  {
    for(int s = 1 ;s<= num-row; s++)
         cout<<" ";
    for(col = 1; col <= row; col++) 
          cout<<"* ";

    cout<<"\n";
  }

  return 0;
}

Output

Please enter the number of rows: 7
* * * * * * * 
 * * * * * * 
  * * * * * 
   * * * * 
    * * * 
     * * 
      *