Reverse Ascending 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 ascending number triangle in C. Each row starts from a decreasing number, but prints upward to the maximum on that row.

The trick is mixing loop directions: the outer loop decrements (to change the starting number), while the inner loop increments (to print ascending values).

⭐ Pattern Output

For rows = 5, the pattern looks like this:

Output
5
45
345
2345
12345
1

Complete C Program

Outer loop counts down to set the row start, inner loop prints from i to rows in ascending order.

c
#include <stdio.h>

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

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

    return 0;
}

🧠 How It Works

1

Choose row count

rows controls the height and the maximum number printed.

Setup
2

Outer loop (start value)

i goes from rows down to 1, setting the first number printed on each row.

Start decreases
3

Inner loop (ascending print)

j starts at i and increments to rows, so each row prints an ascending sequence to the maximum.

Grow to max
4

New line

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

Line break
=

Reverse ascending triangle

Total prints are 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 = i; j <= rows; ++j) {
            printf("%d", j);
        }
        printf("\n");
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Add spaces between digits with printf("%d ", j)
  • Flip inner loop direction to print descending sequences per row
  • Try larger rows to see the triangle grow
  • Combine with stars/spaces for right-aligned variations

Avoid

  • Using an incrementing outer loop (you’ll get a different pattern)
  • Forgetting printf("\n") after each row
  • Not validating input for non-positive rows

Key Takeaways

1

The outer loop decrements to change the starting number each row.

2

The inner loop increments from i to rows to print ascending numbers.

3

Total prints are n(n+1)/2, giving O(n²) time complexity.

4

It’s a great example of mixing loop directions to create new patterns.

❓ Frequently Asked Questions

Because the outer loop starts at i = rows, and the inner loop prints from j = i to rows. When i = rows, only one number is printed.
Yes. Replace printf("%d", j) with printf("%d ", j).
O(n²) because total prints are n+(n-1)+…+1 = n(n+1)/2.

Explore More Number Patterns

Changing where your loops start and end is the fastest way to invent new patterns.

All Number Patterns →
Did you know?

This pattern is a good reminder that “triangle” doesn’t always mean increasing left-to-right. By moving the starting point, you can make the triangle grow upward toward the left.

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