A reverse-start alphabet triangle keeps the right edge fixed at a top letter while each row begins one letter earlier — letters along the row still run forward.
Remember
Rule: for start i from top down to A,
print letters i..top, then newline
E
DE
CDE
BCDE
ABCDE ← top = 'E'
Unlike Program 1 (always starts at A) and Program 2 (prints letters backward along the row), this pattern only moves the first letter; every row still ends at top.
Approach
How to Solve It
Descend the start letter on the outer loop; ascend from that start to top on the inner loop.
Method
Idea
Best for
Compact letters
cout << j with no spaces
Learning, interviews, exams
Spaced letters
cout << j << " "
Readable columns in demos
Pseudocode
Pseudocode
top = 'E' // or 'A' + rows - 1
for i from top down to 'A':
for j from i to top:
print j
print newline
Cheat sheet
Goal
Pattern
Pick the start letter
for (char i = top; i >= 'A'; i--)
Print forward to top
for (char j = i; j <= top; j++)
Print a letter
cout << j;
End the row
cout << "\n";
Top from row count
top = (char)('A' + rows - 1);
Printing Letters vs Starting a New Line
API
Effect
Use for
cout << j
One letter; stays on the line
Each letter in the row
cout << "\n"
Ends the current line
After the letter loop
cout << endl also ends the line (and flushes); "\n" is enough for these demos.
Try it
Live Preview
Change the row count (top = A + n - 1) and the triangle updates instantly — capped at 8 for readability.
Whole numbers from 1 to 8. With n = 5, top is E and you get the classic sample.
Live result5 rows · 15 letters
E
DE
CDE
BCDE
ABCDE
Trace
Worked Walkthrough — top = 'C'
Three rows (n = 3) so each start letter is easy to check by hand.
Start i
Inner j values
Printed row
'C'
C
C
'B'
B, C
BC
'A'
A, B, C
ABC
Every row ends at 'C'; only the first letter moves earlier as i decreases.
Code
C++ Programs
Three complete programs: fixed top letter, cin row count, and a spaced-letter variant. Use View Output to reveal sample results.
Example 1 — Fixed top at 'E'
Hard-coded top — outer loop picks the start; inner loop prints forward to 'E'.
C++
#include <iostream>
using namespace std;
int main()
{
for (char i = 'E'; i >= 'A'; i--)
{
for (char j = i; j <= 'E'; j++)
cout << j;
cout << "\n";
}
return 0;
}
Output
E
DE
CDE
BCDE
ABCDE
How It Works
1. Outer loop moves the start.i runs from 'E' down to 'A' — one row per start letter.
2. Inner loop runs forward. From i up to 'E', so when i = 'C' you get CDE.
3. Right edge stays fixed. Every row ends at 'E'; only the left edge grows leftward.
4. Break the line.cout << "\n" after the letter loop starts the next earlier start.
Example 2 — User Input Version
Read the row count, set top = 'A' + rows - 1, then use the same loops.
C++
#include <iostream>
using namespace std;
int main()
{
int rows;
char top;
cout << "Enter the number of rows: ";
cin >> rows;
top = (char)('A' + rows - 1);
for (char i = top; i >= 'A'; i--)
{
for (char j = i; j <= top; j++)
cout << j;
cout << "\n";
}
return 0;
}
Output (when user enters 4)
Enter the number of rows: 4
D
CD
BCD
ABCD
How It Works
1. Prompt and read.cin >> rows sets how many letters appear on the last row.
2. Compute the top letter. For rows = 4, top becomes 'D'.
3. Same triangle core. Only top changes; start still descends and letters still run forward.
4. Safer input tip. Reject bad or oversized values:
Safer input
if (!(cin >> rows) || rows < 1 || rows > 26)
{
cout << "Enter a whole number from 1 to 26.\n";
return 1;
}
Example 3 — Spaced letters
Same shape with cout << j << " " so letters sit in readable columns.
C++
#include <iostream>
using namespace std;
int main()
{
char top = 'E';
for (char i = top; i >= 'A'; i--)
{
for (char j = i; j <= top; j++)
cout << j << " ";
cout << "\n";
}
return 0;
}
Output
E
D E
C D E
B C D E
A B C D E
How It Works
1. Same loops. Start still descends; letters still run forward to top.
2. Only the print format changes. Appending " " adds a trailing space after each letter.
3. Learn compact first. Use Examples 1–2 when matching exam samples; add spaces when you want clearer columns.
Edge Cases & Pitfalls
Check these before calling the solution done.
Wrong direction
Descending inner loop
If j counts down from top, you get Program 2’s pattern — not this one. Keep j++ from i to top.
Wrong start
Always starting at A
Starting every row at 'A' rebuilds Program 1. The outer start must be i, not a fixed 'A'.
\n early
Broken rows
Call cout << "\n" only after the letter loop finishes.
rows = 1
Single A
Output is just A — one start, one letter.
rows > 26
Past Z
Clamp to 26 for A–Z demos, or define a clear wrap/error policy.
cin
Check failure
Use if (!(cin >> rows)) so bad input does not leave rows uninitialized.
Analysis
Time and Space Complexity
Program
Time
Extra space
Compact (Examples 1–2)
O(n²)
O(1)
Spaced (Example 3)
O(n²)
O(1)
For n rows the letter count is 1 + 2 + … + n = n(n+1)/2 — quadratic in n.
Remember
Key Takeaways
Rule: start at i, print forward to a fixed top.
Outer descends:i from top down to 'A'.
Break the row: call cout << "\n" only after the letter loop.
Complexity:O(n²) time; O(1) extra space.
One line: for each start i from top down to A, print i..top, then cout << "\n".
Frequently Asked Questions
The outer loop moves the starting letter from E down to A. The inner loop always prints forward from that start letter up to E (or top), so the last character remains E on every row.
Program 2 prints letters descending along the row (E, ED, EDC). This program prints forward along the row (E, DE, CDE) while only the row’s first letter moves backward.
Program 1 always starts at A and grows the end letter (A, AB, ABC). This pattern grows the start letter backward while keeping the right edge fixed at top.
cout << j prints a letter and stays on the same line. cout << "\n" ends the current line after the letter loop finishes.
Yes. Read rows from cin and set top = char('A' + rows - 1). Then loop i from top down to 'A' and print j from i up to top.
O(n²) for n rows, because the total printed letters are 1+2+…+n = n(n+1)/2.
After cin >> rows, check failure, require n ≥ 1, and cap at 26 so the top letter stays within A–Z.
Because the inner loop always stops at top (E in the fixed example), so the last printed character is always that same letter.
🤔
Did you know?
This triangle changes only the starting letter of each row (E, D, C, …), while letters along the row still increase forward. In the 5-row example, every row ends at E, producing E, DE, CDE, BCDE, ABCDE.