C++ Program to print half star pyramid pattern
In this article write a C++ Program to print half star pyramid pattern using star * (asterisk). This Program first takes the numbers of rows and uses nested for loops to print half star pyramid pattern.
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;
}