Descending Repeating Number Triangle in C

What You’ll Learn
How to print a descending repeating number triangle in C. Each row repeats the same digit, but the digit decreases on each line while the row length increases.
This pattern is a nice companion to the repeating triangle (Program 9), but with the outer loop running in reverse.
⭐ Pattern Output
For rows = 5, the pattern looks like this:
5
44
333
2222
11111Complete C Program
The outer loop chooses the digit (i) and the inner loop controls how many times it repeats.
#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", i);
}
printf("\n");
}
return 0;
}🧠 How It Works
Setup
rows controls the number of lines and the starting digit.
Outer loop (digit)
i runs from rows down to 1, choosing which digit to repeat on each row.
Inner loop (repeat count)
j runs from rows down to i, so as i gets smaller, the digit repeats more times.
New line
printf("\n") moves to the next row.
Descending repeating triangle
Total prints are 1+2+…+n = n(n+1)/2, so runtime 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", i);
}
printf("\n");
}
return 0;
}💡 Tips for Enhancement
Try These
- Print an ascending repeating triangle by making the outer loop increment
- Add spaces with
printf("%d ", i)for readability - Use characters (A, BB, CCC...) for alphabet repetition patterns
- Try printing on a single line for different shapes
Avoid
- Hard-coding 5 inside loops (use
rows) - Forgetting the newline after each row
- Not validating user input when using
scanf()
Key Takeaways
Each row prints the digit i repeatedly.
The digit decreases because the outer loop counts down from rows.
Repetition increases because the inner-loop range grows as i becomes smaller.
Total prints are n(n+1)/2, so runtime is O(n²).
❓ Frequently Asked Questions
i decreases, the inner loop runs more iterations from rows down to i, so the digit gets printed more times.rows, and keep printing i inside the inner loop.Explore More Pattern Variations
Repeating patterns are a great stepping stone to pyramids and hollow shapes.
This pattern uses the same repetition trick as Program 9—print i inside the inner loop—but flips the outer loop direction to make the digits descend.
12 people found this page helpful
