VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-to-print-inverted-right-half-pyramid-pattern-star-pattern/

⇱ Program to Print Inverted Right Half Pyramid Pattern (Star Pattern) - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to Print Inverted Right Half Pyramid Pattern (Star Pattern)

Last Updated : 30 Jan, 2026

Given an integer N, print N rows of an inverted right half pyramid pattern. In an inverted right half pattern of N rows, the first row has N number of stars, the second row has (N - 1) number of stars, and so on till the Nth row, which has only 1 star.

👁 invertedStarPattern

Examples:

Input: n = 5
Output:
*****
****
***
**
*

Input: n = 3
Output:
***
**
*

Approach

  • Follow these steps to print the inverted right half pyramid pattern using two nested loops.
  • Run the outer loop from i = 1 to N to control the rows.
  • For each iteration of the outer loop, run the inner loop from j = 1 to N - i + 1.
  • Print an asterisk (*) in each iteration of the inner loop.
  • Print a newline after completing the inner loop.
  • Continue until all N rows are printed, forming the inverted right half pyramid.

Output
*****
****
***
**
*

Time Complexity: O(N^2), where N is the number of rows in the pattern.
Auxiliary Space: O(1)

Comment