C++ Program to print half star pyramid pattern

In this article write a C++ Program to print half star pyramid pattern using star * (asterisk).

C++ Program to print half star pyramid pattern

// C++ Program to print half star pyramid pattern

#include <iostream>
using namespace std;

int main()
{
    int i, n, j;

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

    // outer loop is responsible for rows
    for(i = 1; i <= n; i++)
    {

        //inner loop is responsible for columns
        // print * equal to row number
        for(j = 1; j <= i; j++)
        {
            // print stars
            cout << "* ";
        }
        // give line breaks after ending every row
        cout << "\n";
    }
    return 0;
}

When the above C++ program is compile and run, this will produce the following result:

C++ Program to print half star pyramid pattern

Leave A Reply

Your email address will not be published.