Reverse Order Alphabet Triangle in C++

Beginner
⏱️ 5 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Nested Loops

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:

Output
A
BA
CBA
DCBA
EDCBA
1

Complete C++ Program

Outer i runs from 65 ('A') to 69 ('E'). Inner j runs from i down to 65, printing (char) j.

C++
#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

1

Headers and namespace

#include <iostream> and using namespace std; enable cout.

Setup
2

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.

Rows
3

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.

Reverse along row
4

Right edge is always A

The loop ends after j == 65, so the last character printed on every row is 'A'.

Algebra
=

Triangle shape

Same O(n²) work as other letter triangles: 1+2+…+n characters for n rows.

2

Variation — User Input Version

Let base = 65 ('A'). For rows rows, the outer loop runs i from base to base + rows - 1:

C++
#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 of 65 in 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++ with j <= i here—that would print forward, not BA / CBA
  • Letting rows so large that base + rows - 1 leaves the letter range you want
  • Printing j without casting to char

Key Takeaways

1

Increasing i raises the leftmost (highest) letter on each row.

2

Decreasing j prints backward along the row toward 'A'.

3

The last character on every row is always 'A' when base == 65.

4

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.
The inner condition is j >= 65, and 65 is 'A'. The final iteration prints that letter, then j becomes 64 and the loop stops.
Program 3 keeps a fixed right edge at E and moves the start left. Here the left edge moves right (A, B, C, …) and the row always ends at A.
O(n²) for n rows: 1+2+…+n = n(n+1)/2 characters.

Explore More C++ Alphabet Patterns!

Mix ascending rows, descending rows, and mirrored letters to build fluency with ASCII and loops.

All Alphabet Patterns →
Did you know?

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.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful