Hollow Pyramid Pattern
May 25, 2023
ALGORITHM:
- Get the input value n, which represents the number of rows in the hollow pyramid.
- Initialize two loops: an outer loop for rows, i from 0 to n-1, and an inner loop for columns, j from 0 to n-1.
- Repeat the following steps until i reaches n:
a. Check if j is equal to n-i . If true, print a space (" ").
b. Repeat the following steps until j reaches 2*i+1:
- Check if
i
is equal to 0 orj
is equal to 0 orj
is equal to2*i
ori
is equal to n-1 . If true, print an asterisk ("*"). Otherwise, print a space (" "). - Increment
j
by 1.
c. Move to the next line.
d. Increment i
by 1.
4. After the loops complete, the hollow pyramid pattern will be printed.
FLOWCHART: