Descending Repeating Number Triangle in C

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

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:

Output
5
44
333
2222
11111
1

Complete C Program

The outer loop chooses the digit (i) and the inner loop controls how many times it repeats.

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

1

Setup

rows controls the number of lines and the starting digit.

Setup
2

Outer loop (digit)

i runs from rows down to 1, choosing which digit to repeat on each row.

Digit decreases
3

Inner loop (repeat count)

j runs from rows down to i, so as i gets smaller, the digit repeats more times.

Repeat increases
4

New line

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

Line break
=

Descending repeating triangle

Total prints are 1+2+…+n = n(n+1)/2, so runtime 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 = 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

1

Each row prints the digit i repeatedly.

2

The digit decreases because the outer loop counts down from rows.

3

Repetition increases because the inner-loop range grows as i becomes smaller.

4

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

❓ Frequently Asked Questions

Because as i decreases, the inner loop runs more iterations from rows down to i, so the digit gets printed more times.
Make the outer loop increment from 1 to rows, and keep printing i inside the inner loop.
O(n²) because total prints are 1+2+…+n = n(n+1)/2.

Explore More Pattern Variations

Repeating patterns are a great stepping stone to pyramids and hollow shapes.

All Number Patterns →
Did you know?

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.

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