Programs for printing pyramid patterns in C++

// Program to print a pyramid pattern in C++

#include <iostream>
using namespace std;

int main() {
    int rows;
    cout << "Enter the number of rows for the pyramid: ";
    cin >> rows;

    for (int i = 1; i <= rows; i++) {
        for (int j = 1; j <= rows - i; j++) {
            cout << " ";
        }
        for (int k = 1; k <= 2 * i - 1; k++) {
            cout << "*";
        }
        cout << endl;
    }

    return 0;
}

This C++ program prompts the user to enter the number of rows for the pyramid pattern. It then uses nested for loops to iterate through each row and column, printing the appropriate number of spaces and asterisks to form the pyramid pattern. The outer loop controls the number of rows, the first inner loop controls the printing of spaces before the asterisks, and the second inner loop controls the printing of the asterisks. After printing each row, a newline character is used to move to the next line.