Signup/Sign In

Program to print Half Pyramid using * in C++

Following is the program to print Half Pyramid using *.

#include<iostream.h>

int main()
{
    int rows;

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

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

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


Program to print Half Pyramid using number in C++

Following is the program to print Half Pyramid using number.

#include<iostream.h>

int main()
{
    int rows;

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

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

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


Program to print Inverted Half Pyramid using * in C++

Following is the program to print Inverted 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 * * * * * * * * * * * * * * *