Reverse Right-Growing Number Triangle in C

Beginner
⏱️ 5 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Nested Loops

What You’ll Learn

How to print a reverse right-growing number triangle in C. Each row starts from the maximum and extends by one extra digit on every next line.

This pattern is built with two decrementing loops: one to control row length and one to print the descending sequence.

⭐ Pattern Output

For rows = 5, the pattern looks like this:

Output
5
54
543
5432
54321
1

Complete C Program

The outer loop counts down from rows to 1 and the inner loop prints from rows down to i.

c
#include <stdio.h>

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

    for (i = rows; i >= 1; --i) {
        for (j = rows; j >= i; --j) {
            printf("%d", j);
        }
        printf("\n");
    }

    return 0;
}

🧠 How It Works

1

Set rows

rows controls both the height and the maximum digit printed.

Setup
2

Outer loop (row length)

i goes from rows down to 1. As i decreases, the row prints more numbers.

Grow each row
3

Inner loop (print rows..i)

The inner loop starts at rows and decrements to i, printing a descending sequence that gets longer each row.

Descending digits
4

New line

printf("\n") moves to the next row.

Line break
=

Reverse right-growing triangle

Total prints are 1+2+…+n = n(n+1)/2, so time complexity is O(n²).

2

Variation — User Input Version

Accept the number of rows from the user 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 = rows; j >= i; --j) {
            printf("%d", j);
        }
        printf("\n");
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Add spaces with printf("%d ", j)
  • Flip loop directions to create the ascending triangle (Program 5)
  • Right-align by printing leading spaces before each row
  • Try larger rows to see the shape grow

Avoid

  • Mixing loop directions (both must decrement for this exact output)
  • Forgetting the newline after each row
  • Not validating input when using scanf()

Key Takeaways

1

Row length increases because the outer loop decreases i.

2

Digits descend because the inner loop prints from rows down to i.

3

Total prints are n(n+1)/2 so runtime is O(n²).

4

This is the descending counterpart to the basic ascending triangle.

❓ Frequently Asked Questions

Because the outer loop starts at i = rows. The inner loop runs from rows down to i, which prints exactly one digit when i equals rows.
Replace printf("%d", j) with printf("%d ", j).
O(n²) because total prints are 1+2+…+n = n(n+1)/2.

Explore More Number Patterns

Try switching loop bounds to create left-growing and right-growing variations.

All Number Patterns →
Did you know?

Right-growing patterns are mostly about how you control the inner-loop range. Small changes like starting at rows vs 1 can completely change the shape.

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