Reverse Triangle, E Always First in C++

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':
EDCBA
EDCB
EDC
ED
EComplete C++ Program
Outer: i from 65 ('A') to 69 ('E'). Inner: j from 69 down to i, printing (char) j.
#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
Headers and namespace
#include <iostream> and using namespace std; enable cout.
Outer loop raises the floor
i runs 65–69. It is the smallest code j may print on that row, not the first character shown.
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.
Mixed loop directions
Outer i++ and inner j-- are both fine. Row length is 69 - i + 1 characters.
Same total work as other triangles
Still n(n+1)/2 characters for n rows — O(n²).
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:
#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
cinand boundrows
Avoid
- Treating
ias the first printed letter—it is the inner stop, not the first output - Using
j >= 65when you want rows to shorten (that repeats full width) - Confusing this with program 7, where the first letter changes each row
Key Takeaways
Inner loop starts at the top letter every row; outer loop only tightens how far down you go.
Mixed i++ and j-- is normal when the pattern needs them.
O(n²) characters for n rows.
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'.i is 65, j runs down to A. When i is 69, only E prints.Explore More C++ Alphabet Patterns!
Fixing the first letter and sliding the inner bound is a common interview variation on nested loops.
If the inner loop used j >= 65 instead of j >= i, every row would print the full EDCBA string—no shrinking.
12 people found this page helpful
