#include <iostream>
using namespace std;
int main() {
int n;
// Asking the user for the number of rows
cout << "Enter the number of rows for the pyramid: ";
cin >> n;
for (int row = 1; row <= n; row++) {
for (int column = 1; column <= 2 * n - 1; column++) {
if (column >= n - (row - 1) && column <= n + (row - 1)) {
cout << "*";
} else {
cout << " ";
cout << endl;
return 0;
The program asks the user to input the number of rows for the pyramid.
The outer loop runs from 1 to n, representing each row of the pyramid.
The inner loop runs from 1 to 2 * n - 1, representing the number of columns in each row.
The condition column >= n - (row - 1) && column <= n + (row - 1) checks if the
current column should print a * or a space.
The pyramid is symmetrical, so the condition ensures that * is printed in the middle section,
while spaces are printed on either side.