Inverted Repeating-Letter Triangle in C

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

What You’ll Learn

First row: five Es. Each following row is one character shorter and uses the next letter down: EEEEE, DDDD, CCC, BB, A.

Pair with program 9 (width grows, ch++) and program 5 (inverted triangle with changing letters each column).

⭐ Pattern Output

For 5 rows:

Output
EEEEE
DDDD
CCC
BB
A
1

Complete C Program (Fixed Rows)

i controls width (5 down to 1). ch starts at 'E'; after each full row, move to the previous letter.

c
#include <stdio.h>

int main() {
    int i, j;
    char ch = 'E';

    for (i = 5; i >= 1; --i) {
        for (j = 1; j <= i; ++j) {
            printf("%c", ch);
        }
        printf("\n");
        ch--;
    }

    return 0;
}

🧠 How It Works

1

ch = 'E'

The first row is the widest and uses the highest letter in the range. Each shorter row will use the next letter down the alphabet after ch--.

Setup
2

Outer loop i = 5 .. 1

i is both the row counter and how many times you print per row. Counting down makes the triangle invert: five Es, then four Ds, and so on.

Inverted
3

Inner loop: one letter, many times

for (j = 1; j <= i; ++j) calls printf("%c", ch) without updating ch inside the inner loop, so the entire row shows the same character.

Repeat
4

New line, then ch--

printf("\n") finishes the row. Decrementing ch moves backward in ASCII (EDC …) for the next, shorter row.

Next letter
=

Inverted repeat triangle

You still print 5+4+3+2+1 = 15 characters for five rows. For n rows that is n(n+1)/2 prints and O(n²) nested-loop work.

2

Variation — User Input Version

ch = 'A' + rows - 1 picks the letter for the first (widest) row; loop i from rows down to 1.

c
#include <stdio.h>

int main() {
    int rows, i, j;
    char ch;

    printf("Enter the number of rows: ");
    scanf("%d", &rows);

    ch = (char)('A' + rows - 1);

    for (i = rows; i >= 1; --i) {
        for (j = 1; j <= i; ++j) {
            printf("%c", ch);
        }
        printf("\n");
        ch--;
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Equivalent: compute ch = (char)('A' + i - 1) at the start of each outer step if you loop i down without mutating ch
  • Growing repeat triangle: program 9
  • Cap rows or wrap if ch would pass 'A' backward past your intended range

Avoid

  • ch-- inside the inner loop unless you want a staircase of letters
  • Forgetting ch-- so every row stays on 'E'

Key Takeaways

1

Inverted outer loop (5→1) + repeat inner loop = shrinking repeated rows.

2

ch-- once per row keeps each line uniform.

3

O(n²) characters for n rows.

4

Natural complement to program 9 and inverted program 5.

❓ Frequently Asked Questions

i starts at 5, so the inner loop runs five times while ch is still 'E'.
It must run after you finish printing that row’s copies. Putting it right after printf("\n") matches program 9’s style (ch++ after the newline).
ch = 'A' + rows - 1, then for (i = rows; i >= 1; --i) with the same inner loop and ch--.
O(n²) for n rows.

Explore More C Alphabet Patterns!

Inverted width plus ch-- mirrors inverted stars with a letter skin.

All Alphabet Patterns →
Did you know?

You can derive the same output with ch = (char)('A' + i - 1) at the top of each outer iteration while i runs from rows down to 1—no persistent ch-- needed.

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