C++ Program To Print Left Half Pyramid Pattern Last Updated : 23 Feb, 2023 Comments Improve Suggest changes Like Article Like Report Here, we will build a C++ program to print the left half of pyramid pattern using 2 approaches i.e. Using for loopUsing while loop1. Using for loop Input: rows = 5 Output: * ** *** **** ***** First, for loop is used to identify the number of rows and the second for loop is used to identify the number of columns. Here the values will be changed according to the first for loop. If j is greater than i then it will print the output otherwise print the space. C++ // C++ program to print 180 degree rotation of simple // pyramid pattern using for loop #include <iostream> using namespace std; int main() { int rows = 5; // first for loop is used to identify number of rows for (int i = rows; i > 0; i--) { // second for loop is used to identify number of // columns and here the values will be changed // according to the first for loop for (int j = 0; j <= rows; j++) { // if j is greater than i then it will print // the output otherwise print the space if (j >= i) { cout << "*"; } else { cout << " "; } } cout << "\n"; } return 0; } Output * ** *** **** ***** Time complexity: O(n2) Here n is number of rows. Auxiliary Space: O(1) As constant extra space is used. 2. Using while loop Input: rows = 5 Output: * ** *** **** ***** The while loops check the condition until the condition is false. If the condition is true then it enters into the loop and executes the statements. C++ // C++ program to print 180 degree rotation of simple // pyramid pattern using while loop #include <iostream> using namespace std; int main() { int i = 0, j = 0, sp = 0; int rows = 5; // while loop check the condition until the given // condition is false if it is true then enteres in to // the loop while (i < rows) { // second while loop is used for printing spaces while (sp < (rows - i - 1)) { cout << " "; sp++; } // assigning sp value as 0 because we need to run sp // from starting sp = 0; // this loop will print the pattern while (j <= i) { cout << "* "; j++; } j = 0; i++; cout << "\n"; } return 0; } Output * * * * * * * * * * * * * * * Time complexity: O(n2) where n is number of rows Space complexity: O(1) Comment More infoAdvertise with us L laxmigangarajula03 Follow Improve Article Tags : C++ Programs C++ C Pattern Programs Practice Tags : CPP Explore C++ Programming Language 5 min read C++ OverviewIntroduction to C++ Programming Language 3 min read Features of C++ 5 min read History of C++ 7 min read Interesting Facts about C++ 2 min read Setting up C++ Development Environment 8 min read Difference between C and C++ 3 min read C++ BasicsUnderstanding First C++ Program 4 min read C++ Basic Syntax 4 min read C++ Comments 3 min read Tokens in C 4 min read C++ Keywords 2 min read Difference between Keyword and Identifier in C 3 min read C++ Variables and ConstantsC++ Variables 4 min read Constants in C 4 min read Scope of Variables in C++ 7 min read Storage Classes in C++ with Examples 6 min read Static Keyword in C++ 5 min read C++ Data Types and LiteralsC++ Data Types 7 min read Literals in C 4 min read Derived Data Types in C++ 4 min read User Defined Data Types in C++ 4 min read Data Type Ranges and Their Macros in C++ 3 min read C++ Type Modifiers 4 min read Type Conversion in C++ 4 min read Casting Operators in C++ 5 min read C++ OperatorsOperators in C++ 9 min read C++ Arithmetic Operators 4 min read Unary Operators in C 5 min read Bitwise Operators in C 6 min read Assignment Operators in C 4 min read C++ sizeof Operator 3 min read Scope Resolution Operator in C++ 4 min read C++ Input/OutputBasic Input / Output in C++ 5 min read cin in C++ 4 min read cout in C++ 2 min read Standard Error Stream Object - cerr in C++ 2 min read Manipulators in C++ 4 min read C++ Control StatementsDecision Making in C (if , if..else, Nested if, if-else-if ) 7 min read C++ if Statement 3 min read C++ if else Statement 3 min read C++ if else if Ladder 3 min read Switch Statement in C++ 5 min read Jump statements in C++ 4 min read C++ Loops 7 min read for Loop in C++ 6 min read Range-Based for Loop in C++ 3 min read C++ While Loop 3 min read C++ do while Loop 4 min read C++ FunctionsFunctions in C++ 8 min read return Statement in C++ 4 min read Parameter Passing Techniques in C 3 min read Difference Between Call by Value and Call by Reference in C 4 min read Default Arguments in C++ 5 min read Inline Functions in C++ 6 min read Lambda Expression in C++ 4 min read C++ Pointers and ReferencesPointers and References in C++ 5 min read C++ Pointers 8 min read Dangling, Void , Null and Wild Pointers in C 6 min read Applications of Pointers in C 4 min read Understanding nullptr in C++ 3 min read References in C++ 5 min read Can References Refer to Invalid Location in C++? 2 min read Pointers vs References in C++ 5 min read Passing By Pointer vs Passing By Reference in C++ 5 min read When do we pass arguments by pointer? 5 min read Like