Half Pyramid Pattern in C++ language of Stars using For loop
ADVERTISEMENTS
Half pyramid pattern in c++ language of stars using for loop. In this article, you will learn how to draw the half pyramid pattern in c++ language of stars using for loop.
Source Code
// Half Pyramid Pattern in C++ language of Stars using For loop
#include <iostream>
using namespace std;
int main() {
int r = 0, i, j;
// r - denotes the number of rows
cout << "-----To print the half pyramid enter the number of rows-----\n";
cin >> r;
cout << "\n";
for (i = 1; i <= r; ++i) {
for (j = 1; j <= i; ++j)
cout << "* ";
cout << "\n";
}
return 0;
}
Output
-----To print the half pyramid enter the number of rows-----
8
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *