Reverse Order Alphabet Triangle in C++

What You’ll Learn
Build a right-angled triangle where the first character of each row moves forward in the alphabet (A, B, C, D, E), but each row is printed backward down to A: A, BA, CBA, DCBA, EDCBA.
Compare with program 1 (forward A, AB, ABC, …) and program 3 (left edge moves backward, letters forward along the row).
⭐ Pattern Output
For 5 rows:
A
BA
CBA
DCBA
EDCBAComplete C++ Program
Outer i runs from 65 ('A') to 69 ('E'). Inner j runs from i down to 65, printing (char) j.
#include <iostream>
using namespace std;
int main() {
int i, j;
for (i = 65; i <= 69; i++) {
for (j = i; j >= 65; j--)
cout << (char) j;
cout << "\n";
}
return 0;
}🧠 How It Works
Headers and namespace
#include <iostream> and using namespace std; enable cout.
Outer loop: grow the row
for (i = 65; i <= 69; i++) picks the highest letter on each row: A, B, C, D, E. Row length equals i - 65 + 1.
Inner loop: print descending
for (j = i; j >= 65; j--) prints from the row’s high letter down to 'A'. Each step uses cout << (char) j.
Right edge is always A
The loop ends after j == 65, so the last character printed on every row is 'A'.
Triangle shape
Same O(n²) work as other letter triangles: 1+2+…+n characters for n rows.
Variation — User Input Version
Let base = 65 ('A'). For rows rows, the outer loop runs i from base to base + rows - 1:
#include <iostream>
using namespace std;
int main() {
int rows;
int i, j;
const int base = 65;
cout << "Enter the number of rows: ";
cin >> rows;
for (i = base; i < base + rows; i++) {
for (j = i; j >= base; j--)
cout << (char) j;
cout << "\n";
}
return 0;
}💡 Tips for Enhancement
Try These
- Use
'A'instead of65in conditions for readability - Use
static_cast<char>(j)instead of(char) j - For A, AB, ABC, … see program 1
- Try lowercase with
base = 97('a')
Avoid
- Using
j++withj <= ihere—that would print forward, not BA / CBA - Letting
rowsso large thatbase + rows - 1leaves the letter range you want - Printing
jwithout casting tochar
Key Takeaways
Increasing i raises the leftmost (highest) letter on each row.
Decreasing j prints backward along the row toward 'A'.
The last character on every row is always 'A' when base == 65.
Time complexity O(n²) for n rows.
❓ Frequently Asked Questions
j starts at i and counts down to 65. Each cout << (char) j prints one step lower in the alphabet until you reach A.j >= 65, and 65 is 'A'. The final iteration prints that letter, then j becomes 64 and the loop stops.Explore More C++ Alphabet Patterns!
Mix ascending rows, descending rows, and mirrored letters to build fluency with ASCII and loops.
This pattern is the row-wise complement of program 1 in a sense: program 1 walks j upward from A; here j walks downward from i to A, so the left column grows A, B, C, … while the right column stays A.
12 people found this page helpful
