Triangle with Reverse Starting Letter in C++

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

What You’ll Learn

This pattern mixes ideas from program 1 and program 2: each row is longer than the last, the first character moves backward in the alphabet, but along the row letters still run forward.

With five rows and right edge 'E' (ASCII 69), you get E, DE, CDE, BCDE, ABCDE.

⭐ Pattern Output

For 5 rows and top letter 'E':

Output
E
DE
CDE
BCDE
ABCDE
1

Complete C++ Program

Outer i steps down from 69 to 65. Inner j runs from i up to 69, printing (char) j each time.

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

int main() {
    int i, j;
    for (i = 69; i >= 65; i--) {
        for (j = i; j <= 69; 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: move the start left

for (i = 69; i >= 65; i--) picks the first ASCII code on each row: E, D, C, B, A.

Left edge
3

Inner loop: print forward to E

for (j = i; j <= 69; j++) prints consecutive letters from the row start up to 'E'. cout << (char) j converts codes to letters.

Inner
4

Straight right edge

Because j always ends at 69, the last character on every row is 'E'—the right side of the triangle lines up.

Right edge
=

Reverse start, forward run

Total characters: 1+2+…+n = n(n+1)/2, so time complexity is O(n²) for n rows.

2

Variation — User Input Version

Keep the right edge at 'E' (code 69) like the classic example. Run the outer loop from 69 down to 70 - rows so you get exactly rows lines:

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

int main() {
    int rows;
    int i, j;
    const int top = 69;

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

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

    return 0;
}

💡 Tips for Enhancement

Try These

  • Replace 69 with 'E' in loop bounds for readability
  • Compare with program 1 (A, AB, ABC) and program 2 (E, ED, EDC)
  • Change top to another letter code to move the whole pattern
  • Add leading spaces to right-align the triangle

Avoid

  • Using j >= i with j-- here—that is program 2’s shape, not this one
  • Letting rows so large that i drops below 'A' unless you intend non-letters
  • Printing j without (char) (you would see numbers)

Key Takeaways

1

Decreasing i moves the row’s first letter left in the alphabet while j still counts up along the row.

2

j from i to 69 keeps the last character on every row at 'E' in the five-row setup.

3

For variable rows with a fixed right edge top, use i >= top - rows + 1 in the outer condition.

4

Same O(n²) cost as other triangle letter patterns.

❓ Frequently Asked Questions

The outer loop variable i is that letter’s ASCII code. It starts at 69 ('E') and counts down, so the first character goes E, D, C, B, A.
The inner loop stops when j passes 69, so the last value printed is always (char) 69, i.e. 'E'.
Program 2 walks backward along the row (j from 69 down to i). Here j runs forward from i to 69, so you see DE, not ED.
O(n²) for n rows: 1+2+…+n = n(n+1)/2 characters.

Explore More C++ Alphabet Patterns!

Character arithmetic plus nested loops unlock many interview-style shapes.

All Alphabet Patterns →
Did you know?

Because j always reaches the same top code, the right margin of the pattern is vertical—like a column of 'E' characters stacked in the output.

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