Ascending Repeating Shrinking Pattern in C

What You’ll Learn
How to print an ascending repeating number shrinking pattern in C. The digit increases each row, but the number of repeats decreases each row.
This is a great exercise to learn how expressions like rows - i + 1 can control the inner-loop length.
⭐ Pattern Output
For rows = 5, the pattern looks like this:
11111
2222
333
44
5Complete C Program
The inner loop runs rows - i + 1 times, which shrinks the row as i increases.
#include <stdio.h>
int main() {
int rows = 5;
int i, j;
for (i = 1; i <= rows; ++i) {
for (j = 1; j <= rows - i + 1; ++j) {
printf("%d", i);
}
printf("\n");
}
return 0;
}🧠 How It Works
Set rows
rows is the maximum digit and also controls triangle height.
Outer loop (digit)
i increases from 1 to rows, choosing the digit to repeat on each row.
Inner loop (repeat count)
rows - i + 1 gives the repetition count. It decreases by one each row, shrinking the line length.
New line
printf("\n") completes the row.
Shrinking repetition
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 = 1; i <= rows; ++i) {
for (j = 1; j <= rows - i + 1; ++j) {
printf("%d", i);
}
printf("\n");
}
return 0;
}💡 Tips for Enhancement
Try These
- Make it grow by using
j <= iinstead ofrows - i + 1 - Add spaces with
printf("%d ", i) - Try letters instead of digits for AAAA, BBB, CC...
- Right-align by adding leading spaces before each row
Avoid
- Hard-coding the row count
- Forgetting the newline after each row
- Using negative rows without validation
Key Takeaways
The printed digit is the row index i.
The repetition count is rows - i + 1, which decreases each row.
Total prints are n(n+1)/2, so runtime is O(n²).
This is the shrinking counterpart to repeating triangles like Program 9.
❓ Frequently Asked Questions
rows - i + 1 times, which decreases as i increases.for (j = 1; j <= i; ++j) so each next row prints one more digit.Explore More Pattern Variations
Try combining repetition rules with alternating row logic for new zigzag patterns.
The expression rows - i + 1 is a common trick for shrinking patterns. You’ll see it again in inverted triangles and right-aligned shapes.
12 people found this page helpful
