Print half pyramid - C++ Program

Q. Write a C++ program to print the half pyramid.

half pyramid

Answer:

#include<iostream>
using namespace std;
int main()
{
        int i, j, cnt;
        cout<<"\n Enter Number of Rows : ";
        cin>>cnt;
        cout<<"\n";
        for(i=0; i<cnt; i++)
        {
                for(j=0; j<=i; j++)
                {
                        cout<<" * ";
                }
                cout<<"\n";
        }
        return 0;
}


Output:

half pyramid