C++ Repeating Alphabet Triangle Pattern (Inverted)
Beginner
6 min read
Updated: Sep 2026
3 programs
Live preview
Definition
What Is This Pattern?
An inverted repeating alphabet triangle prints a wide first row of one letter, then shrinks by one repeated letter on each new line while letters count down.
Remember
Rule: width i from rows down to 1;
print ch exactly i times, then ch--
EEEEE
DDDD
CCC
BB
A ← 5 rows (start ch = 'E')
It is the flip of Program 10: same countdown letters, but widths shrink 5, 4, 3, …, 1 instead of growing. Print ch in the inner loop, then ch-- after each row so every line stays uniform.
Approach
How to Solve It
Two ways to emit the same shape — start with nested loops + ch--, then optionally polish with string(n, ch).
Method
Idea
Best for
Nested loops + ch--
Outer = shrinking width; print ch, then decrement
Learning, interviews, exams
string(repeat, ch)
One call builds a full repeated-letter row
Short demos once loops click
Pseudocode
Pseudocode
ch = 'A' + rows - 1
for i from rows down to 1:
for j from 1 to i:
print ch (no newline)
print newline
ch = ch - 1
if (!(cin >> rows) || rows < 1 || rows > 26) {
cout << "Enter a whole number from 1 to 26.\n";
return 1;
}
Example 3 — string(repeat, ch)
Build each repeated-letter row in one call — same shape without an explicit inner print loop.
C++
#include <iostream>
#include <string>
using namespace std;
int main() {
int rows = 5;
char top = (char)('A' + rows - 1);
for (char ch = top; ch >= 'A'; ch--) {
int repeat = ch - 'A' + 1;
cout << string(repeat, ch) << "\n";
}
return 0;
}
Output
EEEEE
DDDD
CCC
BB
A
How It Works
1. Map letter to width.repeat = ch - 'A' + 1 — E repeats 5 times, D four times, down to A once.
2. Build the row.string(repeat, ch) creates a string of length repeat filled with ch.
3. Print once. One cout per row replaces the inner letter loop.
Learn the nested-loop version first (Examples 1–2); treat string(n, ch) as a polish shortcut afterward.
Edge Cases & Pitfalls
Check these before calling the solution done.
cout j
Stepping letters on a row
If you print j instead of ch, the row is no longer uniform. Always print ch.
ch-- inside
Letters change mid-row
Put ch-- after the inner loop and newline. Decrementing inside the letter loop steps characters across the row.
\n inside
Column of letters
If cout << "\n" is inside the inner loop, each letter lands on its own line. End the row only after all repeats.
rows > 26
Past Z
'A' + rows - 1 leaves A–Z when rows > 26. Clamp or reject in interactive programs.
rows = 1
Single A
Output is just A — top and tip coincide. A good sanity check.
cin fail
Check the stream
If cin fails, rows may be unset — always test if (!(cin >> rows)) and prefer 1–26.
Analysis
Time and Space Complexity
Program
Time
Extra space
Nested loops (Examples 1–2)
O(rows²)
O(1)
string(n, ch) (Example 3)
O(rows²)
O(row width) temporary per row
Total letters = n + (n - 1) + … + 1 = n(n + 1)/2 — still quadratic in n. Same totals as Program 10; only the print order of widths differs.
Remember
Key Takeaways
Rule: shrink width i; print ch exactly i times; then ch--.
Flip of Program 10: same letters — widths shrink instead of grow.
Break then step:cout << "\n" first, then ch-- for the next shorter row.
Complexity:O(n²) time; O(1) extra space for the loop form.
One line: for each shrinking width, print ch that many times, then cout << "\n" and ch--.
Frequently Asked Questions
Program 10 prints widths 1..5 (E, DD, CCC, ...). Program 11 prints widths 5..1 (EEEEE, DDDD, ...). Both use repeating letters per row and letters counting down.
i starts at 5 so the first inner loop runs five times while ch is E. After the row, ch becomes D and i is 4, so the next line prints D four times.
So every column on a row shows the same letter. Decrementing inside the inner loop would step letters across the row.
j only controls how many times the loop runs. Printing ch keeps the entire row the same letter; printing j would step letters across the row.
cout << ch stays on the same line. cout << "\n" ends the current line. Letters use cout << ch; the row break uses cout << "\n" after the inner loop.
O(n²) where n is the number of rows. Total letter prints equal n+(n-1)+…+1 = n(n+1)/2.
Yes. cout << string(repeat, ch) << "\n" prints a full repeated-letter row in one call. Nested loops are better for learning; the string constructor is a handy shortcut later.
After cin >> rows, check failure: if (!(cin >> rows)) handle bad input. Then set ch = 'A' + rows - 1 and loop i from rows down to 1 with ch-- after each row. Clamp to 26 for A–Z demos.
🤔
Did you know?
This is the inverted twin of Program 10: letters still step E→A, but widths shrink 5, 4, 3, …, 1 instead of growing. Print ch in the inner loop, then ch-- after each row so every line stays uniform.