Write a Simple Pyramid Pattern program in C++ with for loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <iostream> using namespace std; int main() { int n; // Taking input from user cout << "Enter the number of rows: "; cin >> n; // Generating the pyramid pattern for (int i = 1; i <= n; ++i) { // Printing spaces for (int j = i; j < n; ++j) { cout << " "; } // Printing stars for (int k = 1; k <= (2 * i - 1); ++k) { cout << "*"; } // Moving to the next line cout << endl; } return 0; } |
Output
