Reverse Repeating-Letter Triangle in C

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

What You’ll Learn

Same repeating idea as program 9, but letters run E → D → C → B → A while row widths still grow 1, 2, 3, 4, 5.

Use ch = 'E' - i + 1 at the start of each outer iteration (for five rows ending at E).

⭐ Pattern Output

For 5 rows:

Output
E
DD
CCC
BBBB
AAAAA
1

Complete C Program (Fixed Rows)

'E' - i + 1 is equivalent to (char)('E' - (i - 1)): row 1 uses E, row 2 uses D, and so on.

c
#include <stdio.h>

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

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

    return 0;
}

🧠 How It Works

1

Outer loop: row i

i runs 1 to 5. Row i always prints i characters, so the shape is a growing triangle of repeats, same geometry as other “one letter per row” examples.

Width
2

ch = 'E' - i + 1

At the start of each outer iteration you derive the letter from i and the fixed top letter E. For i = 1 you get E; for i = 5 you get A. No persistent ch++ is needed.

Letter per row
3

Inner loop: repeat the derived letter

printf("%c", ch) runs i times. Because ch is recomputed from i at the top of the outer body, each full row stays one solid letter.

Repeat
4

New line only

printf("\n") ends the row. The next i changes both the repeat count and the letter from the same formula, so letters descend ED → … while the row grows wider.

No ch++
=

Formula vs. stepping ch

Two valid styles: keep one ch and increment it each row, or compute ch from i and a ceiling letter. Both yield n(n+1)/2 prints and O(n²) nested loops for n rows.

2

Variation — User Input Version

startChar = 'A' + rows - 1 is the top letter (E when rows == 5). Then ch = startChar - i + 1.

c
#include <stdio.h>

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

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

    startChar = 'A' + rows - 1;

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

    return 0;
}

💡 Tips for Enhancement

Try These

  • Forward repeat triangle: ch = (char)('A' + i - 1)program 9
  • Inverted widths with repeats (e.g. EEEEE, DDDD, …) by changing the outer loop over i
  • Lowercase: shift startChar with 'a'

Avoid

  • Using ch++ and this formula in the same loop unless you mean to combine ideas
  • Rows so large that startChar - i + 1 drops below 'A' unintentionally

Key Takeaways

1

ch = top - i + 1 gives descending letters for row indices 1…n.

2

Inner loop still only repeats; it does not pick the letter.

3

O(n²) characters for n rows.

4

Dual of program 9: ascending letters vs descending letters, same triangle shape.

❓ Frequently Asked Questions

Integer promotion applies: 'E' and i combine arithmetically, then the result is stored in ch. For i = 1..5 you get E, D, C, B, A.
Then every row would print the same letter. The formula ties the letter to the row index.
startChar = 'A' + rows - 1, then ch = startChar - i + 1 for i = 1..rows.
O(n²) for n rows.

Explore More C Alphabet Patterns!

One formula on ch often replaces several manual updates.

All Alphabet Patterns →
Did you know?

'E' - i + 1 equals 'A' + (5 - i) for five rows—same letters, two ways to think about it.

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