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

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

C++
#include <iostream>
using namespace std;

int main() {
    int i, j;
    for (i = 65; i <= 69; i++) {
        for (j = 69; j >= i; j--)
            cout << (char) j;
        cout << "\n";
    }
    return 0;
}

🧠 How It Works

1

Headers and namespace

#include <iostream> and using namespace std; enable cout.

Setup
2

Outer loop raises the floor

i runs 6569. It is the smallest code j may print on that row, not the first character shown.

Lower bound
3

Inner loop always starts at E

j starts at 69 every row, so the leftmost output is always 'E'. j >= i stops the tail earlier as i grows.

Fixed first letter
4

Mixed loop directions

Outer i++ and inner j-- are both fine. Row length is 69 - i + 1 characters.

5 … 1
=

Same total work as other triangles

Still n(n+1)/2 characters for n rows — O(n²).

2

Variation — User Input Version

endCode = 65 + rows - 1 is the top letter (inner start) and the top of the outer range. i runs from 65 to endCode:

C++
#include <iostream>
using namespace std;

int main() {
    int rows;
    int i, j;
    const int base = 65;

    cout << "Enter the number of rows: ";
    cin >> rows;

    int endCode = base + rows - 1;
    for (i = base; i <= endCode; i++) {
        for (j = endCode; j >= i; j--)
            cout << (char) j;
        cout << "\n";
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Use 'A' and 'E' in the fixed five-row version instead of 65 and 69 if you prefer
  • Relate to program 2 (E-anchored rows with a different inner rule)
  • Lowercase: base = 97, endCode = 97 + rows - 1
  • Validate cin and bound rows

Avoid

  • Treating i as the first printed letter—it is the inner stop, not the first output
  • Using j >= 65 when you want rows to shorten (that repeats 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 i++ and j-- is normal when the pattern needs them.

3

O(n²) characters for n rows.

4

Contrasts with program 6: fixed E on the left vs growing forward to E.

❓ Frequently Asked Questions

j always initializes to 69, so the first cout on each line is always 'E'.
The lowest letter printed on that row. When i is 65, j runs down to A. When i is 69, only E prints.
Program 7 decreases the first letter each row (E, D, C, …). Here the first letter stays E; only the tail shortens.
O(n²) for n rows: n(n+1)/2 characters.

Explore More C++ Alphabet Patterns!

Fixing the first letter and sliding the inner bound is a common interview variation on nested loops.

All Alphabet Patterns →
Did you know?

If the inner loop used j >= 65 instead of j >= i, every row would print the full EDCBA string—no shrinking.

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