Inverted Repeating-Letter Triangle in C++

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

What You’ll Learn

First row: five Es. Each following row is one character shorter and uses the next letter down: EEEEE, DDDD, CCC, BB, A.

Compare with program 9 (width grows, ch++ style) and program 10 (width grows with letters E→A). This page matches the classic codetofun C++ loop: j from 65 to i.

⭐ Pattern Output

For 5 rows:

Output
EEEEE
DDDD
CCC
BB
A
1

Complete C++ Program

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

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) i;
        cout << "\n";
    }
    return 0;
}

🧠 How It Works

1

Headers and namespace

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

Setup
2

Outer loop: row letter

for (i = 69; i >= 65; i--) walks E, D, C, B, A. That ASCII value is both the symbol and the upper bound for j.

Descending letter
3

Inner loop: repeat count

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

Shrinking width
4

New line

cout << "\n" ends the row; i-- picks the next (shorter) row.

Next row
=

Shrinking repeat rows

Row lengths are n, n−1, …, 1, so total output is n(n+1)/2 characters — O(n²) for n starting width.

2

Variation — User Input Version

Let base = 65 and top = base + rows - 1. Outer i from top down to base; inner j from base 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 = top; i >= base; i--) {
        for (j = base; j <= i; j++)
            cout << (char) i;
        cout << "\n";
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Growing repeat triangle: program 9
  • Growing width, letters E→A: program 10
  • Char style: char ch = 'A' + rows - 1, outer i from rows to 1, inner j to i, then ch-- after each row
  • Lowercase: set base = 97

Avoid

  • cout << (char) j unless you want A, B, C… across the row
  • Mixing program-10 inner bounds (j from top down) with this outer i — the geometry won’t match

Key Takeaways

1

Outer i sets the letter; inner j from base to i sets how many copies.

2

Row length = i - base + 1 — shrinks as i steps down.

3

O(n²) characters for n rows.

4

Complement to programs 9 and 10: inverted width with repeated letters.

❓ Frequently Asked Questions

i starts at 69 ('E'), and j runs from 65 through 69—five values—each printing (char) i.
That would print a staircase of letters along the row. Here every column on a row must show the same letter i.
Program 10 uses inner j from top down to i (narrow-to-wide rows). Program 11 uses j from base up to i (wide-to-narrow rows).
O(n²) for n rows: n(n+1)/2 characters.

Explore More C++ Alphabet Patterns!

Programs 10 and 11 both walk i from E down to A; the inner loop bounds choose growing vs shrinking row width.

All Alphabet Patterns →
Did you know?

The C-style version keeps a char ch, loops i from rows down to 1, prints ch i times, then ch--. Same picture; this page’s C++ sample folds letter and width into one ASCII outer index i.

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