C++ Program To Print Right Half Pyramid Pattern Last Updated : 23 Feb, 2023 Comments Improve Suggest changes 2 Likes Like Report Here we will build a C++ Program To Print Right Half Pyramid Pattern with the following 2 approaches: Using for loop Using while loop Input: rows = 5 Output: * * * * * * * * * * * * * * * 1. Using for loop 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. C++ // C++ Program To Print Right Half // 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 = 1; i <= rows; 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 = 1; j <= i; j++) { // printing the required pattern cout << "* "; } cout << "\n"; } return 0; } Output* * * * * * * * * * * * * * * Time complexity: O(n2) Here n is number of rows. Space complexity: O(1) As constant extra space is used. 2. Using while loop The while loops check the condition until the condition is false. If condition is true then enters in to loop and execute the statements. C++ // C++ Program To Print Right Half // Pyramid Pattern using while loop #include <iostream> using namespace std; int main() { int i = 0, j = 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) { // 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) Create Quiz Comment L laxmigangarajula03 Follow 2 Improve L laxmigangarajula03 Follow 2 Improve Article Tags : C++ Programs C++ C Pattern Programs Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like