Inverted Forward Repeating Triangle in C++

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

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:

Output
AAAAA
BBBB
CCC
DD
E
1

Complete C++ Program

Outer i from 65 up to 69. Inner j from 69 down to i; each iteration prints (char) i.

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

1

Headers and namespace

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

Setup
2

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.

Ascending i
3

Inner loop: shrinking width

for (j = 69; j >= i; j--) runs 69 - i + 1 times. Each time, cout << (char) i repeats the same letter.

Repeat
4

New line

cout << "\n" ends the row; i++ moves to the next letter (and shorter row).

Next row
=

Fifteen characters for five rows

Same total as programs 9 and 11 — O(n²) for n rows.

2

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:

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 = 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', outer i from rows to 1, inner j to i, then ch++ 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) j unless you want letters stepping along the row
  • Decrementing i on the outer loop when you need A→E row order

Key Takeaways

1

Inverted width plus ascending i gives forward letters on a shrinking triangle.

2

Inner count = top - i + 1 with fixed top = 69 in the five-row demo.

3

O(n²) characters for n rows.

4

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.
Program 11 uses outer 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.
O(n²) for n rows: n(n+1)/2 characters.

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.

All Alphabet Patterns →
Did you know?

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.

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