logoStarPatterns
Back to Patterns

Reverse Right Half Pyramid

Pattern Result

*****
****
***
**
*

Code Implementation

Explanation

The Reverse Right Half Pyramid pattern creates an inverted triangle shape that is aligned to the right side. Each row starts with spaces followed by stars. As the row number increases, the number of spaces increases and the number of stars decreases. The outer loop iterates from n down to 1, representing each row. For each row, we first add (n - i) spaces to create the right alignment, and then add i stars to create the inverted pyramid shape.