![]() |
VOOZH | about |
Here we will build a C++ Program To Print Right Half Pyramid Pattern with the following 2 approaches:
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.
* * * * * * * * * * * * * * *
Time complexity: O(n2)
Here n is number of rows.
Space complexity: O(1)
As constant extra space is used.
The while loops check the condition until the condition is false. If condition is true then enters in to loop and execute the statements.
* * * * * * * * * * * * * * *
Time complexity: O(n2) where n is number of rows
Space complexity: O(1)