C++ Online Compiler
Example: Inverted Full Pyramid Pattern in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Inverted Full Pyramid Pattern #include <iostream> using namespace std; int main() { // Step 1: Declare variable for number of rows int rows; // Step 2: Prompt user for input cout << "Enter the number of rows for the inverted full pyramid: "; cin >> rows; // Step 3: Outer loop for rows (from rows down to 1) for (int i = rows; i >= 1; --i) { // Step 4: Inner loop to print leading spaces // Number of spaces increases with each row (as i decreases) for (int j = 0; j < rows - i; ++j) { cout << " "; } // Step 5: Inner loop to print asterisks // Number of asterisks decreases: (2*i - 1) for (int k = 1; k <= 2 * i - 1; ++k) { cout << "*"; } // Step 6: Move to the next line after each row cout << endl; } return 0; }
Output
Clear
ADVERTISEMENTS