Row-Based Descending Number Pattern in C

Beginner
⏱️ 5 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Nested Loops

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:

Output
1
21
321
4321
54321
1

Complete C Program

The outer loop sets the row number, and the inner loop prints from i down to 1.

c
#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

1

Row count

rows sets how many lines to print.

Setup
2

Outer loop (rows)

i increases from 1 to rows. Each iteration prints one row, and the row length becomes i.

Grow the triangle
3

Inner loop (count down)

j starts at i and decrements to 1, printing the descending sequence on that row.

Descending row
4

New line

printf("\n") moves to the next row.

Line break
=

Row-based descending pattern

Total prints are 1+2+…+n = n(n+1)/2, so time complexity is O(n²).

2

Variation — User Input Version

Accept the number of rows from the user using scanf():

c
#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

1

Row i prints a countdown from i to 1.

2

The inner loop direction (--j) is what makes each row descend.

3

Total prints are n(n+1)/2, so runtime is O(n²).

4

Switching the inner loop to 1..i gives the ascending triangle (Program 5).

❓ Frequently Asked Questions

Because the inner loop starts at j = i, and i is the current row index.
Change the inner loop to for (j = 1; j <= i; ++j) and print j.
O(n²) because total prints are 1+2+…+n = n(n+1)/2.

Keep Practicing Patterns

Try combining row-based logic with right-alignment or spacing to invent new variations.

All Number Patterns →
Did you know?

Row-based patterns are common in interviews because you can derive the inner-loop range directly from the row index.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful