⚡ TL;DR
Print the inverted right angle triangle (half pyramid) star pattern in C using nested for loops. Full source code with output, explanation, and complexity analysis.
In this program, we will see the inverted right angle triangle pyramid pattern (also called the reverse half triangle pattern) in the C programming language using stars. Each row contains one fewer star than the previous row, shrinking from n stars down to 1.
Pattern to Print
*****
****
***
**
*Implementation
The C program for the above inverted right angle triangle pyramid pattern is as follows:
#include<stdio.h>
int main() {
int i, j, noRows;
printf("Enter number of rows for pattern = ");
scanf("%d",&noRows);
for(i=noRows-1; i>=0; i--) {
for(j=0;j<=i;j++) {
printf("*");
}
printf("\n");
}
return 0;
}Output
Enter number of rows for pattern = 5
*****
****
***
**
*How It Works
This is the mirror image of Star Pattern Series 1 — the only difference is the direction of the outer loop:
- Outer loop (
i) — counts down fromnoRows - 1to0, so the first row printed is the widest. - Inner loop (
j) — still runsi + 1times per row (j <= i). On the first passi = 4, so 5 stars print; on the last passi = 0, so just 1 star prints. - Newline —
printf("\n")ends each row.
Because the inner loop condition j <= i is unchanged, flipping the outer loop’s direction is all it takes to invert the triangle.
Complexity
- Time: O(n²) — total stars printed = n + (n-1) + … + 1 = n(n+1)/2
- Space: O(1) — only loop counters are used
Practice Variations
- Combine this pattern with Series 1 to print a full diamond-like hourglass shape
- Add leading spaces so the inverted triangle is right-aligned
- Replace
*with descending row numbers - Rewrite the same pattern using
whileloops instead offorloops
Happy coding!
References
- C language reference — cppreference
printfin C — cppreferencescanfin C — cppreference- GCC online documentation — GNU
FAQ
How do I print an inverted triangle star pattern in C?
Use two nested for loops with the outer loop counting down instead of up: start i at noRows-1 and decrement it to 0. The inner loop still prints i+1 stars under the condition j <= i, so the first row shows n stars and each subsequent row loses one until a single star remains.
Why does the outer loop count down in the inverted pyramid program?
Because the direction of the outer loop decides row width. Counting down makes the first pass use the largest index, so the widest row prints first and every later row is one star narrower. The inner loop condition j <= i needs no change at all — flipping the outer loop alone inverts the triangle.
What is the time and space complexity of the inverted star pattern in C?
Time complexity is O(n²) because the program prints n + (n-1) + … + 1 stars, totaling n(n+1)/2 print operations. Space complexity is O(1): only the two loop counters and the row count are stored, so memory usage stays constant whether the user asks for 5 rows or 500.
How do I convert a half pyramid into a full pyramid or diamond in C?
Add leading spaces before the stars so each row is centered, turning the half pyramid into a full pyramid. Combining a normal triangle with an inverted one produces a diamond-like hourglass shape. The number of leading spaces follows a simple formula that shrinks as each row’s star count grows, keeping every row visually aligned.

Written by Mihir Pipermitwala
Senior Full Stack Consultant & Mobile Engineering Specialist building user-focused applications in healthcare with Flutter, Dart and React Native. I write about what I actually build and test — every tutorial here comes from real project work.
More about Mihir →