Reverse Triangle, E Always First in C

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

What You’ll Learn

Every line begins with 'E' and runs backward in the alphabet, but lines get shorter: EDCBA, EDCB, EDC, ED, E.

Compare program 7 (left edge steps E→D→C→ …) and program 6 (left edge steps A→B→ … toward E).

⭐ Pattern Output

For five rows with top letter 'E':

Output
EDCBA
EDCB
EDC
ED
E
1

Complete C Program (ASCII Values)

Outer: i from 65 ('A') to 69 ('E'). Inner: j from 69 down to i.

c
#include <stdio.h>

int main() {
    int i, j;

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

    return 0;
}

Same with characters: for (i = 'A'; i <= 'E'; ++i) and for (j = 'E'; j >= i; --j).

🧠 How It Works

1

Outer loop raises the floor

i counts 'A' through 'E'. It is not printed first; it is the smallest code the inner loop may reach on that row.

Lower bound
2

Inner loop always starts at E

j starts at 69 every time, so the leftmost output is always 'E'.

Fixed first letter
3

j >= i

When i == 'A', j runs E down to A (five letters). When i == 'E', only j == E runs (one letter).

Shrinking tail
4

Characters per row

Row with bound i prints 69 - i + 1 characters (for ASCII E and AE range).

5, 4, 3, 2, 1
=

Mixed loop directions

Outer ++ and inner -- are both fine in C; total work is still O(n²) for n rows in the general version.

2

Variation — User Input Version

endChar = 'A' + rows - 1 is both the first character each line prints (inner start) and the top of the outer range. i still runs from 'A' to endChar.

c
#include <stdio.h>

int main() {
    int rows, i, j;
    int endChar;

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

    endChar = 'A' + rows - 1;

    for (i = 'A'; i <= endChar; ++i) {
        for (j = endChar; j >= i; --j) {
            printf("%c", j);
        }
        printf("\n");
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Rewrite with only char variables if you prefer
  • Lowercase: set endChar = 'a' + rows - 1 and start inner at that letter
  • Relate to program 2 (also repeats an E-anchored idea per row, different inner rule)
  • Validate scanf and bound rows

Avoid

  • Thinking i is the first letter printed—it is the inner loop stop, not the first output
  • Using j >= 65 when you want shortening rows (that would repeat full width)
  • Confusing this with program 7 where the first letter changes each row

Key Takeaways

1

Inner loop starts at the top letter every row; outer loop only tightens how far down you go.

2

Mixed ++ and -- loops are normal when the pattern needs them.

3

O(n²) characters for n rows.

4

Dual of program 6 in a sense: fixed right end vs fixed left start (E).

❓ Frequently Asked Questions

j always initializes to 69 ('E') before counting down, so the first printf on each line is E.
It is the smallest value j may reach on that row. Larger i means a shorter run from E down to i.
Program 7 lowers the starting letter each row (E, D, C, …). Here the first letter stays E; only the tail length changes.
O(n²) for n rows.

Explore More C Alphabet Patterns!

One loop forward and one backward is a common way to clip a triangle from a fixed corner.

All Alphabet Patterns →
Did you know?

The left column is always E and the right column steps A, B, C, D, E—the mirror of patterns where the right column is fixed and the left moves.

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