Reverse Descending Number Triangle in C

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:
54321
4321
321
21
1Complete C Program
Both loops decrement: outer loop sets the row start value and inner loop prints down to 1.
#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
Rows and counters
rows = 5 controls the triangle height. i and j are loop counters.
Outer loop (row start)
for (i = rows; i >= 1; --i) decreases the first number printed on each row: 5, then 4, then 3, ...
Inner loop (count down)
for (j = i; j >= 1; --j) prints descending numbers on the row, ending at 1.
New line
printf("\n") moves to the next row after the inner loop finishes.
Reverse descending triangle
Total prints are 1+2+…+n = n(n+1)/2, so the program runs in O(n²) time for n rows.
Variation — User Input Version
Let the user choose the row count 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 >= 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
The outer loop sets the starting number for each row by counting down from rows.
The inner loop prints descending numbers from i down to 1.
Total prints form a triangular number: n(n+1)/2, so time complexity is O(n²).
This pattern is the reverse counterpart to the descending number triangle.
❓ Frequently Asked Questions
j from i down to 1, printing a countdown on each row.i from rows to 1, so each new row begins with a smaller number.for (i = 1; i <= rows; ++i) and for (j = 1; j <= i; ++j).Explore More Number Patterns
Try adjusting loop directions and bounds to create new triangles, pyramids, and mirrored patterns.
To get this exact output, both loops must decrement. If the inner loop increments, you’ll get a different pattern (like 12345, 1234...).
12 people found this page helpful
