Inverted Right-Angled Triangle Star Pattern in C

Beginner
⏱️ 5 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Reverse iteration

What You'll Learn

How to print an inverted right-angled triangle star pattern in C using nested for loops. The outer loop counts down from the number of rows, so the first row has the most stars and each following row has one fewer—the mirror image of the classic right triangle.

With rows = 5, the pattern runs from five stars down to one.

⭐ Pattern Output

When you run the program with rows = 5, you’ll see this output:

Output
*****
****
***
**
*
1

Complete C Program

Here’s the complete C program that prints the inverted right-angled triangle star pattern:

c
#include <stdio.h>

int main() {
    int rows = 5;
    int i, j;

    for (i = rows; i >= 1; --i) {
        for (j = 1; j <= i; ++j) {
            printf("*");
        }
        printf("\n");
    }

    return 0;
}

🧠 How It Works

1

Declare Variables

int rows = 5; sets the number of stars in the first row. Variables i and j are loop counters for rows and stars per row.

Setup
2

Outer Loop (Rows, Reverse)

for (i = rows; i >= 1; --i) starts at the widest row and moves down to one star. Each value of i is how many stars that row prints.

Row control
3

Inner Loop (Stars)

for (j = 1; j <= i; ++j) calls printf("*") exactly i times per row. The inner bound still equals the current row’s star count; the outer loop counts down instead of up.

Star printing
4

New Line

printf("\n") after the inner loop finishes one row and prepares the next.

Line break
=

Inverted triangle

Decreasing i prints the wide row first. Total stars still n(n+1)/2O(n²) time, O(1) extra space. Wide first lines use the same scrollable glyph area on narrow viewports.

2

Variation — User Input Version

Let the user decide the number of rows at runtime using scanf():

c
#include <stdio.h>

int main() {
    int rows;
    int i, j;

    printf("Enter the number of rows: ");
    scanf("%d", &rows);

    for (i = rows; i >= 1; --i) {
        for (j = 1; j <= i; ++j) {
            printf("*");
        }
        printf("\n");
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Use scanf() so row count is chosen at runtime
  • Switch the outer loop to 1..rows and print rows - i + 1 stars for the same shape
  • Print numbers (12345, 1234, …) instead of *
  • Build a hollow inverted triangle (border stars only)
  • Compare side-by-side with the standard right-angled triangle from Program 1

Avoid

  • Forgetting printf("\n") after each row
  • Mixing up i >= 1 and i > 0 without adjusting the inner bound
  • Using scanf() without checking that rows is positive
  • Assuming the inner loop must always run 1..i when a formula could also work
  • Hard-coding 5 when you meant to use the rows variable

Key Takeaways

1

The outer loop runs from rows down to 1; the inner loop prints that many stars per row.

2

Row with i = k prints exactly k stars—so the first row is the widest.

3

Time complexity is still O(n²) for n rows; only the loop direction changed.

4

You can implement the same shape with a forward outer loop and (rows - i + 1) stars in the inner loop.

5

This pattern pairs naturally with the upright triangle—master both to read nested loops in either direction.

❓ Frequently Asked Questions

The outer loop starts from rows and decrements to 1. For each i, the inner loop prints i stars, so the first line is longest and each line shrinks by one—an upside-down right triangle.
The standard triangle uses for (i = 1; i <= rows; ++i) (stars grow each row). This one uses for (i = rows; i >= 1; --i) (stars shrink each row).
Yes. Use for (i = 1; i <= rows; ++i) and print (rows - i + 1) stars in the inner loop. Both approaches yield the same output.
The time complexity is O(n²) where n is the number of rows. Total stars printed are still n(n+1)/2.

Explore More C Star Patterns!

From pyramids and diamonds to hollow shapes and number patterns—master nested loops with 11+ pattern programs.

All Star Patterns →
Did you know?

The inverted right-angled triangle uses the same inner loop as the upright version—only the outer loop’s direction changes. Learning both back-to-back is one of the fastest ways to internalize nested loops.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful