Inverted Repeating-Letter Triangle in C++

What You’ll Learn
First row: five Es. Each following row is one character shorter and uses the next letter down: EEEEE, DDDD, CCC, BB, A.
Compare with program 9 (width grows, ch++ style) and program 10 (width grows with letters E→A). This page matches the classic codetofun C++ loop: j from 65 to i.
⭐ Pattern Output
For 5 rows:
EEEEE
DDDD
CCC
BB
AComplete C++ Program
Outer i from 69 down to 65. Inner j from 65 up to i; each iteration prints (char) i.
#include <iostream>
using namespace std;
int main() {
int i, j;
for (i = 69; i >= 65; i--) {
for (j = 65; j <= i; j++)
cout << (char) i;
cout << "\n";
}
return 0;
}🧠 How It Works
Headers and namespace
#include <iostream> and using namespace std; enable cout.
Outer loop: row letter
for (i = 69; i >= 65; i--) walks E, D, C, B, A. That ASCII value is both the symbol and the upper bound for j.
Inner loop: repeat count
for (j = 65; j <= i; j++) runs i - 65 + 1 times. Each time, cout << (char) i prints the same letter.
New line
cout << "\n" ends the row; i-- picks the next (shorter) row.
Shrinking repeat rows
Row lengths are n, n−1, …, 1, so total output is n(n+1)/2 characters — O(n²) for n starting width.
Variation — User Input Version
Let base = 65 and top = base + rows - 1. Outer i from top down to base; inner j from base to i:
#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 top = base + rows - 1;
for (i = top; i >= base; i--) {
for (j = base; j <= i; j++)
cout << (char) i;
cout << "\n";
}
return 0;
}💡 Tips for Enhancement
Try These
- Growing repeat triangle: program 9
- Growing width, letters E→A: program 10
- Char style:
char ch = 'A' + rows - 1, outerifromrowsto1, innerjtoi, thench--after each row - Lowercase: set
base = 97
Avoid
cout << (char) junless you want A, B, C… across the row- Mixing program-10 inner bounds (
jfromtopdown) with this outeri— the geometry won’t match
Key Takeaways
Outer i sets the letter; inner j from base to i sets how many copies.
Row length = i - base + 1 — shrinks as i steps down.
O(n²) characters for n rows.
Complement to programs 9 and 10: inverted width with repeated letters.
❓ Frequently Asked Questions
i starts at 69 ('E'), and j runs from 65 through 69—five values—each printing (char) i.i.j from top down to i (narrow-to-wide rows). Program 11 uses j from base up to i (wide-to-narrow rows).Explore More C++ Alphabet Patterns!
Programs 10 and 11 both walk i from E down to A; the inner loop bounds choose growing vs shrinking row width.
The C-style version keeps a char ch, loops i from rows down to 1, prints ch i times, then ch--. Same picture; this page’s C++ sample folds letter and width into one ASCII outer index i.
12 people found this page helpful
