An increasing-start alphabet triangle keeps a fixed end letter on every row, but moves the start one letter later each line — so the left edge walks forward while the right edge stays put.
Remember
Rule: on row with start i, print i..end
ABCDE
BCDE
CDE
DE
E ← 5 rows (end = 'E')
Compare with Program 5 (same widths, but every row restarts at A and shortens the end) and Program 3 (grows while starting earlier toward a fixed end).
Approach
How to Solve It
Two ways to emit the same shape — classic nested char loops, or spaced letters for readability.
Method
Idea
Best for
Nested char loops
Outer picks start i; inner prints i..end
Learning, interviews, exams
Spaced letters
Same bounds; print j << " "
Clearer console demos once loops click
Pseudocode
Pseudocode
endChar = 'A' + rows - 1
for i from 'A' to endChar:
for j from i to endChar:
print j (no newline)
print newline
Cheat sheet
Goal
Pattern
End letter
char endChar = char('A' + rows - 1);
Advance start
for (char i = 'A'; i <= endChar; i++)
Print i..end
for (char j = i; j <= endChar; j++) cout << j;
End the row
cout << "\n";
vs Program 5
Program 5: start fixed at A, end shrinks
Letter total
n + (n−1) + … + 1 = n(n+1)/2
Printing Letters vs Starting a New Line
API
Effect
Use for
cout << j
Stays on the same line
Each letter
cout << "\n"
Ends the current line
After the inner loop finishes a row
Print letters without a newline, then end the row once.
Try it
Live Preview
Change the row count and the triangle updates instantly — every row still ends on the same letter.
Whole numbers from 1 to 10. Tap a chip or type a value — the preview redraws as you go.
Live result5 rows · end E · 15 letters
ABCDE
BCDE
CDE
DE
E
Trace
Worked Walkthrough — End = E (5 rows)
Trace each start letter i and the suffix that runs to the fixed end.
i (start)
Inner range
Printed row
Letters
A
A..E
ABCDE
5
B
B..E
BCDE
4
C
C..E
CDE
3
D
D..E
DE
2
E
E..E
E
1
Total letter prints: 5 + 4 + 3 + 2 + 1 = 15 = 5×6/2. The right edge is always E; that triangular sum is why time is O(n²).
Code
C++ Programs
Three complete programs: fixed A–E, row-count input, and a spaced-letter variant. Use View Output to reveal sample results.
Example 1 — Fixed End E
Hard-coded height — outer loop advances the start; inner loop always stops at E.
C++
#include <iostream>
using namespace std;
int main()
{
for (char i = 'A'; i <= 'E'; i++)
{
for (char j = i; j <= 'E'; j++)
cout << j;
cout << "\n";
}
return 0;
}
Output
ABCDE
BCDE
CDE
DE
E
How It Works
1. Outer loop picks the start.i runs from 'A' to 'E' — each row begins one letter later.
2. Inner loop runs to a fixed end. For each i, j runs from i to 'E', so every row ends with E.
3. Break the line.cout << "\n" after the inner loop starts the next (shorter) row.
When i = 'C' you get CDE; when i = 'E' you get E.
Example 2 — Row Count Input
Read the number of rows and compute endChar = 'A' + rows - 1. Prefer validating cin in real apps.
C++
#include <iostream>
using namespace std;
int main()
{
int rows;
cout << "Enter the number of rows: ";
cin >> rows;
char endChar = char('A' + rows - 1);
for (char i = 'A'; i <= endChar; i++)
{
for (char j = i; j <= endChar; j++)
cout << j;
cout << "\n";
}
return 0;
}
Output (when user enters 4)
Enter the number of rows: 4
ABCD
BCD
CD
D
How It Works
1. Scale with rows. For 4 rows, endChar becomes 'D'. Cap rows at 26 so endChar stays within A–Z.
2. Same nested-loop core. Only the source of endChar changes — the print logic matches Example 1.
3. Safer input tip. Prefer:
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 bounds — print a trailing space after each letter so columns are easier to scan.
C++
#include <iostream>
using namespace std;
int main()
{
char endChar = 'E';
for (char i = 'A'; i <= endChar; i++)
{
for (char j = i; j <= endChar; j++)
cout << j << " ";
cout << "\n";
}
return 0;
}
Output
A B C D E
B C D E
C D E
D E
E
How It Works
1. Bounds unchanged. Outer still advances i; inner still walks i..endChar.
2. Only the printed unit changes. Each cell becomes j + " ". Trim trailing spaces later if you need a compact line.
Edge Cases & Pitfalls
Check these before calling the solution done.
j from A
Wrong cousin pattern
If the inner loop starts at 'A' instead of i, you get Program 1 / Program 5 style prefixes. Start at i for this suffix triangle.
\n early
Column of letters
If cout << "\n" is inside the inner loop, each letter lands on its own line. Print letters without a newline; end the row only after the inner loop.
end shrinks
Confused with Program 5
Program 5 keeps start at A and shrinks the end. This pattern keeps the end fixed and advances the start.
rows = 1
Single A
Output is just A on one line — a good sanity check.
rows > 26
Beyond Z
Cap or reject — endChar leaves the alphabet. Keep rows in 1…26 for A–Z demos.
Bad cin
Validate rows
Check cin >> rows, require a positive whole number, and clamp to 26 before building endChar.
Analysis
Time and Space Complexity
Program
Time
Extra space
Nested loops (Examples 1–2)
O(n²)
O(1)
Spaced letters (Example 3)
O(n²)
O(1)
Total letters printed = n + (n−1) + … + 1 = n(n+1)/2, which is still quadratic in n.
Remember
Key Takeaways
Rule: start advances each row; end letter stays fixed.
Two loops: outer picks start i; inner prints i..end.
Break the row:cout << "\n" only after the inner loop.
Complexity:O(n²) time; O(1) extra space.
One line: for each start i from A to end, print i..end, then a newline.
Frequently Asked Questions
The outer loop picks the starting letter (A, then B, then C…). The inner loop prints from that start up to the fixed end letter (E in the 5-row example). Each row drops the leftmost character and becomes shorter.
Program 5 restarts each row at A and shortens the end letter (ABCDE, ABCD, …). Program 6 shifts the start letter forward each row while keeping the same end letter (ABCDE, BCDE, …).
Program 3 grows while starting earlier (E, DE, CDE). This pattern shrinks while starting later (ABCDE, BCDE, CDE). Both keep a fixed right edge at the top letter.
Because the inner loop always stops at the same end letter ('E'), so the last printed character is fixed.
O(n²) for n rows, because total printed characters are n+(n−1)+…+1 = n(n+1)/2.
Yes. Read rows from cin, set endChar = char('A' + rows - 1), then loop i from 'A' to endChar and print j from i up to endChar.
After cin >> rows, check failure, require n ≥ 1, and cap at 26 so the end letter stays within A–Z.
Yes. Use 'a' as the base: endChar = char('a' + rows - 1), then loop the same way with j from i up to endChar.
🤔
Did you know?
Each row starts one letter later (A, B, C, …), but always prints up to the same end letter. For 5 rows, the output is ABCDE, BCDE, CDE, DE, E.