Inverted Forward Repeating Triangle in C++

What You’ll Learn
Row width shrinks from five to one, but the letter moves forward each row: AAAAA, BBBB, CCC, DD, E.
Compare program 11 (same inverted shape, letters step down from E) and program 9 (width grows with forward letters).
⭐ Pattern Output
For 5 rows:
AAAAA
BBBB
CCC
DD
EComplete C++ Program
Outer i from 65 up to 69. Inner j from 69 down to i; each iteration prints (char) i.
#include <iostream>
using namespace std;
int main() {
int i, j;
for (i = 65; i <= 69; i++) {
for (j = 69; 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: forward letter
for (i = 65; i <= 69; i++) walks A, B, C, D, E. That value is what you print on every cell of the row.
Inner loop: shrinking width
for (j = 69; j >= i; j--) runs 69 - i + 1 times. Each time, cout << (char) i repeats the same letter.
New line
cout << "\n" ends the row; i++ moves to the next letter (and shorter row).
Fifteen characters for five rows
Same total as programs 9 and 11 — O(n²) for n rows.
Variation — User Input Version
Let base = 65 and top = base + rows - 1. Outer i from base to top; inner j from top down 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 = base; i <= top; i++) {
for (j = top; j >= i; j--)
cout << (char) i;
cout << "\n";
}
return 0;
}💡 Tips for Enhancement
Try These
- Char style:
ch = 'A', outerifromrowsto1, innerjtoi, thench++after each row (same picture as the C tutorial) - Inverted with descending letters: program 11
- Growing triangle: program 9
- Lowercase: use
base = 97
Avoid
cout << (char) junless you want letters stepping along the row- Decrementing
ion the outer loop when you need A→E row order
Key Takeaways
Inverted width plus ascending i gives forward letters on a shrinking triangle.
Inner count = top - i + 1 with fixed top = 69 in the five-row demo.
O(n²) characters for n rows.
Dual of program 11; like program 9 with the outer letter loop paired to shrinking widths.
❓ Frequently Asked Questions
i starts at 65 ('A'), and j runs from 69 down to 65—five iterations—each printing (char) i.i descending (E→A) with j from base to i. Program 12 uses outer i ascending (A→E) with j from top down to i.top = 65 + rows - 1, then for (i = 65; i <= top; i++) with inner j from top to i.Explore More C++ Alphabet Patterns!
Programs 11 and 12 share the same inverted widths; only whether i counts down from E or up from A changes the letter order.
You can derive the letter without mutating ch: at the start of each outer step, (char) i already is the row’s symbol; the inner loop only counts how many times to print it.
12 people found this page helpful
