Inverted Right-Angled Alphabet Triangle in C++

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

What You’ll Learn

Print an inverted letter triangle: the first row is the longest (ABCDE for five rows), then each row drops one letter while still starting from 'A' and counting up to the current upper bound.

This pairs with program 1 (growing rows). Here the outer loop runs the high letter from E down to A instead of growing the row width from A upward.

⭐ Pattern Output

For 5 rows:

Output
ABCDE
ABCD
ABC
AB
A
1

Complete C++ Program

Outer i from 69 down to 65; inner j from 65 to i, printing (char) j.

C++
#include <iostream>
using namespace std;

int main() {
    int i, j;
    for (i = 69; i >= 65; i--) {
        for (j = 65; j <= i; 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 shrinks the row

for (i = 69; i >= 65; i--) sets the last letter on the row: E, then D, then C, … Smaller i means a shorter inner loop.

Width shrinks
3

Inner loop always starts at A

for (j = 65; j <= i; j++) prints A through the letter with code i. Each new row resets implicitly because j starts at 65 again.

Fresh A prefix
4

New line

cout << "\n" after the inner loop ends the row before i decreases.

Line break
=

Inverted triangle

Total characters: n(n+1)/2 for n rows — O(n²).

2

Variation — User Input Version

Let base = 65 ('A') and top = base + rows - 1. Run i from top down to base:

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;

    int top = base + rows - 1;
    for (i = top; i >= base; i--) {
        for (j = base; j <= i; j++)
            cout << (char) j;
        cout << "\n";
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Write 'A' and 'E' instead of 65 and 69 in the fixed five-row version
  • For the growing triangle, use program 1
  • Use base = 97 for a lowercase inverted triangle
  • Compare with inverted stars in C++ star pattern 2

Avoid

  • Incrementing i on the outer loop when you need the row width to shrink
  • Starting j at i here—that would change the pattern (see programs 3 and 4)
  • Printing j without casting to char

Key Takeaways

1

Counting i down from the top letter code shortens each row while the inner loop always begins at 'A'.

2

j from 65 to i prints a contiguous forward slice of the alphabet on each line.

3

For variable rows, set top = 65 + rows - 1 and loop i from top down to 65.

4

Same total work as program 1: O(n²) characters for n rows.

❓ Frequently Asked Questions

When i is 69, the inner loop prints five letters. Each time i drops by one, the inner loop runs one fewer iteration, so the rows get shorter.
65 is 'A'. Resetting the inner loop to A each outer iteration gives ABCDE, then ABCD, then ABC, and so on—not one long alphabet across lines.
Program 1 increases the upper bound so lines grow. Here the upper bound i decreases, so lines shrink. The inner “A through bound” idea is the same.
O(n²) for n rows: still n(n+1)/2 printed characters.

Explore More C++ Alphabet Patterns!

Inverted shapes are the same loop tricks as growing triangles—only the outer bound changes direction.

All Alphabet Patterns →
Did you know?

If you swap the outer loop to count up from 65 to 69 with the same inner j loop, you get program 1’s output (A, AB, ABC, …) instead of an inverted triangle.

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