C++ Online Compiler
Example: Half Pyramid Pattern in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Half 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 half pyramid: "; cin >> rows; // Step 3: Outer loop for rows for (int i = 1; i <= rows; ++i) { // Step 4: Inner loop to print asterisks // Number of asterisks is equal to the current row number for (int j = 1; j <= i; ++j) { cout << "* "; // Added a space for better visual separation } // Step 5: Move to the next line after each row cout << endl; } return 0; }
Output
Clear
ADVERTISEMENTS