Reverse Right-Growing Number Triangle in C

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:
5
54
543
5432
54321Complete C Program
The outer loop counts down from rows to 1 and the inner loop prints from rows down to i.
#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
Set rows
rows controls both the height and the maximum digit printed.
Outer loop (row length)
i goes from rows down to 1. As i decreases, the row prints more numbers.
Inner loop (print rows..i)
The inner loop starts at rows and decrements to i, printing a descending sequence that gets longer each row.
New line
printf("\n") moves to the next row.
Reverse right-growing triangle
Total prints are 1+2+…+n = 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 = 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
Row length increases because the outer loop decreases i.
Digits descend because the inner loop prints from rows down to i.
Total prints are n(n+1)/2 so runtime is O(n²).
This is the descending counterpart to the basic ascending triangle.
❓ Frequently Asked Questions
i = rows. The inner loop runs from rows down to i, which prints exactly one digit when i equals rows.printf("%d", j) with printf("%d ", j).Explore More Number Patterns
Try switching loop bounds to create left-growing and right-growing variations.
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.
12 people found this page helpful
