Reverse Descending 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 descending number triangle in C using nested loops. Each row counts down to 1, and the starting number decreases on every next row.

This pattern is a great exercise for understanding decrementing loops and how to control both the row start and the per-row sequence.

⭐ Pattern Output

For rows = 5, the pattern looks like this:

Output
54321
4321
321
21
1
1

Complete C Program

Both loops decrement: outer loop sets the row start value and inner loop prints down to 1.

c
#include <stdio.h>

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

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

    return 0;
}

🧠 How It Works

1

Rows and counters

rows = 5 controls the triangle height. i and j are loop counters.

Setup
2

Outer loop (row start)

for (i = rows; i >= 1; --i) decreases the first number printed on each row: 5, then 4, then 3, ...

Start decreases
3

Inner loop (count down)

for (j = i; j >= 1; --j) prints descending numbers on the row, ending at 1.

Descending row
4

New line

printf("\n") moves to the next row after the inner loop finishes.

Line break
=

Reverse descending triangle

Total prints are 1+2+…+n = n(n+1)/2, so the program runs in O(n²) time for n rows.

2

Variation — User Input Version

Let the user choose the row count 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 = i; j >= 1; --j) {
            printf("%d", j);
        }
        printf("\n");
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Accept row count from the user with scanf()
  • Add spaces between numbers with printf("%d ", j)
  • Make an ascending triangle by changing both loops to increment
  • Right-align the output by printing leading spaces before each row
  • Combine with other patterns to create mirrored designs

Avoid

  • Mixing up loop directions (both should decrement for this exact pattern)
  • Forgetting printf("\n") after each row
  • Using non-positive rows without validating input

Key Takeaways

1

The outer loop sets the starting number for each row by counting down from rows.

2

The inner loop prints descending numbers from i down to 1.

3

Total prints form a triangular number: n(n+1)/2, so time complexity is O(n²).

4

This pattern is the reverse counterpart to the descending number triangle.

❓ Frequently Asked Questions

Because the inner loop decrements j from i down to 1, printing a countdown on each row.
The outer loop decreases i from rows to 1, so each new row begins with a smaller number.
Change both loops to increment: for (i = 1; i <= rows; ++i) and for (j = 1; j <= i; ++j).
O(n²) because total prints are 1+2+…+n = n(n+1)/2.

Explore More Number Patterns

Try adjusting loop directions and bounds to create new triangles, pyramids, and mirrored patterns.

All Number Patterns →
Did you know?

To get this exact output, both loops must decrement. If the inner loop increments, you’ll get a different pattern (like 12345, 1234...).

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