Signup/Sign In

C++ Program To Print Reverse Half Pyramid

Here our task is to print the required pattern without actually writing it manually. We will see how to do this for a reverse half pyramid pattern. The simplest case will be to make the pattern using * only.

Following is the program to print reverse Half Pyramid using *.

#include<iostream.h>

int main()
{
    int rows;

    cout << "Enter number of rows: ";
    cin >> rows;

    for(int i = rows; i >= 1; --i)
    {
        for(int j = 1; j <= i; ++j)
        {
            cout << "*"<< " ";
        }
        cout << "\n";
    }
getch();
return 0 ;
}


Enter number of rows: 5
* * * * *
* * * *
* * *
* *
*

Now we will proceed towards a little difficult task: arrange the numbers in the form of a half pyramid using the same concept.

#include <iostream>
using namespace std;

int main()
{
    int rows;

    cout << "Enter number of rows: ";
    cin >> rows;

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

    return 0;
}


Enter number of rows: 5
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Conclusion

As for the implementation part, we can use alphabets, or any other symbol for the pattern but the general will remain the same for always.



About the author:
Nikita Pandey is a talented author and expert in programming languages such as C, C++, and Java. Her writing is informative, engaging, and offers practical insights and tips for programmers at all levels.