Reverse Ascending Number Triangle in C

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:
5
45
345
2345
12345Complete C Program
Outer loop counts down to set the row start, inner loop prints from i to rows in ascending order.
#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
Choose row count
rows controls the height and the maximum number printed.
Outer loop (start value)
i goes from rows down to 1, setting the first number printed on each row.
Inner loop (ascending print)
j starts at i and increments to rows, so each row prints an ascending sequence to the maximum.
New line
printf("\n") moves to the next row.
Reverse ascending triangle
Total prints are n(n+1)/2, so time complexity is O(n²).
Variation — User Input Version
Accept the number of rows from the user using scanf():
#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
rowsto 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
The outer loop decrements to change the starting number each row.
The inner loop increments from i to rows to print ascending numbers.
Total prints are n(n+1)/2, giving O(n²) time complexity.
It’s a great example of mixing loop directions to create new patterns.
❓ Frequently Asked Questions
i = rows, and the inner loop prints from j = i to rows. When i = rows, only one number is printed.printf("%d", j) with printf("%d ", j).Explore More Number Patterns
Changing where your loops start and end is the fastest way to invent new patterns.
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.
12 people found this page helpful
