Triangle with Reverse Starting Letter in C++

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':
E
DE
CDE
BCDE
ABCDEComplete C++ Program
Outer i steps down from 69 to 65. Inner j runs from i up to 69, printing (char) j each time.
#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
Headers and namespace
#include <iostream> and using namespace std; enable cout.
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.
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.
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.
Reverse start, forward run
Total characters: 1+2+…+n = n(n+1)/2, so time complexity is O(n²) for n rows.
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:
#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
Avoid
- Using
j >= iwithj--here—that is program 2’s shape, not this one - Letting
rowsso large thatidrops below'A'unless you intend non-letters - Printing
jwithout(char)(you would see numbers)
Key Takeaways
Decreasing i moves the row’s first letter left in the alphabet while j still counts up along the row.
j from i to 69 keeps the last character on every row at 'E' in the five-row setup.
For variable rows with a fixed right edge top, use i >= top - rows + 1 in the outer condition.
Same O(n²) cost as other triangle letter patterns.
❓ Frequently Asked Questions
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.j passes 69, so the last value printed is always (char) 69, i.e. 'E'.j from 69 down to i). Here j runs forward from i to 69, so you see DE, not ED.Explore More C++ Alphabet Patterns!
Character arithmetic plus nested loops unlock many interview-style shapes.
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.
12 people found this page helpful
