Row-Based Descending Number Pattern in C

What You’ll Learn
How to print a row-based descending number pattern in C. Row i prints numbers from i down to 1.
This is a perfect example of mixing loop directions: the outer loop increments (row grows), while the inner loop decrements (numbers count down).
⭐ Pattern Output
For rows = 5, the pattern looks like this:
1
21
321
4321
54321Complete C Program
The outer loop sets the row number, and the inner loop prints from i down to 1.
#include <stdio.h>
int main() {
int rows = 5;
int i, j;
for (i = 1; i <= rows; ++i) {
for (j = i; j >= 1; --j) {
printf("%d", j);
}
printf("\n");
}
return 0;
}🧠 How It Works
Row count
rows sets how many lines to print.
Outer loop (rows)
i increases from 1 to rows. Each iteration prints one row, and the row length becomes i.
Inner loop (count down)
j starts at i and decrements to 1, printing the descending sequence on that row.
New line
printf("\n") moves to the next row.
Row-based descending pattern
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 = 1; i <= rows; ++i) {
for (j = i; j >= 1; --j) {
printf("%d", j);
}
printf("\n");
}
return 0;
}💡 Tips for Enhancement
Try These
- Print ascending rows by switching the inner loop to
1..i - Add spaces between digits with
printf("%d ", j) - Right-align by printing leading spaces before each row
- Try a continuous counter if you want 1, 32, 654, ...
Avoid
- Forgetting the newline after each row
- Using non-positive row counts without validation
- Printing separators inconsistently across rows
Key Takeaways
Row i prints a countdown from i to 1.
The inner loop direction (--j) is what makes each row descend.
Total prints are n(n+1)/2, so runtime is O(n²).
Switching the inner loop to 1..i gives the ascending triangle (Program 5).
❓ Frequently Asked Questions
j = i, and i is the current row index.for (j = 1; j <= i; ++j) and print j.Keep Practicing Patterns
Try combining row-based logic with right-alignment or spacing to invent new variations.
Row-based patterns are common in interviews because you can derive the inner-loop range directly from the row index.
12 people found this page helpful
