To print a right half pyramid pattern in C++, you can use nested loops to control the number of rows and columns printed.
In this example,
n
to represent the number of rows in the pyramid.cout << '*'
to print asterisks (*) for the pyramid structure in each row.cout << endl
to move to the next line after each row.#include <iostream>
using namespace std;
int main() {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
cout << '*';
}
cout << endl;
}
return 0;
}
* ** *** **** *****
In this tutorial, we learned How to print Right Half Pyramid Pattern in C++ language with well detailed examples.