C++ Repeating Alphabet Triangle Pattern (Reverse)

Beginner
6 min read
Updated: Sep 2026
3 programs
Live preview

What Is This Pattern?

A reverse repeating alphabet triangle grows by one repeated letter on each new line while letters count downward from the top of the alphabet range.

Remember
Rule: for letter i from top down to 'A',
      print i with growing width 1, 2, 3, …

E
DD
CCC
BBBB
AAAAA     ← 5 rows (top = 'E')

It is the reverse of Program 9: same growing widths, but letters step E → A instead of A → E. Print the outer letter inside the inner loop so each row stays uniform. Flip the widths in Program 11 to get the inverted twin.

How to Solve It

Two ways to emit the same shape — start with nested char loops and cout, then optionally polish with string(n, ch).

MethodIdeaBest for
Nested loops + coutOuter = letter; inner = growing width; print outer letterLearning, interviews, exams
string(repeat, ch)One call builds a full repeated-letter rowShort demos once loops click

Pseudocode

Pseudocode
for i from top down to 'A':
    for j from top down to i:
        print i (no newline)
    print newline

Cheat sheet

GoalPattern
Countdown lettersfor (char i = top; i >= 'A'; i--)
Grow widthfor (char j = top; j >= i; j--)
Uniform rowcout << i; — print i, not j
End the rowcout << "\n";
Top from rowstop = (char)('A' + rows - 1);
string shortcutcout << string(repeat, ch) << "\n";
Forward twinProgram 9 (A, BB, CCC, …)

Printing Letters vs Starting a New Line

APIEffectUse for
cout << iStays on the same lineEach repeated letter on the row
cout << "\n"Ends the current lineAfter the inner loop

Print characters without a newline, then end the row once.

Live Preview

Change the height and the reverse repeating triangle updates instantly — capped at 26 letters (A–Z).

Whole numbers from 1 to 26. Tap a chip or type a value — the preview redraws as you go.

Live result 5 rows · 15 letters
E
DD
CCC
BBBB
AAAAA

Worked Walkthrough — 'E' down to 'A'

Trace each outer-loop value of i and count how many times the inner loop runs.

iInner j rangePrinted rowRepeats
'E''E'..'E'E1
'D''E'..'D'DD2
'C''E'..'C'CCC3
'B''E'..'B'BBBB4
'A''E'..'A'AAAAA5

Total letter prints: 1 + 2 + 3 + 4 + 5 = 15 = 5×6/2. That triangular sum is why time is O(n²).

C++ Programs

Three complete programs: fixed letters, cin input, and a string shortcut. Use View Output to reveal sample results.

Example 1 — Fixed 'E' down to 'A'

Hard-coded range — outer letter counts down; inner loop grows and prints that letter.

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

int main() {
    char i, j;

    for (i = 'E'; i >= 'A'; i--) {
        for (j = 'E'; j >= i; j--) {
            cout << i;
        }
        cout << "\n";
    }

    return 0;
}

How It Works

1. Outer loop picks the letter. i runs from 'E' down to 'A'.

2. Inner loop sets the width. j runs from 'E' down to i — once for E, twice for D, and so on.

3. Print the outer letter. cout << i keeps the whole row the same character.

4. Break the line. cout << "\n" after the inner loop starts the next row.

Example 2 — User Input Version

Read the row count with cin, set top = 'A' + rows - 1, then use the same countdown core. Always check cin in real apps.

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

int main() {
    int rows;
    char i, j, top;

    cout << "Enter the number of rows: ";
    cin >> rows;
    top = (char)('A' + rows - 1);

    for (i = top; i >= 'A'; i--) {
        for (j = top; j >= i; j--) {
            cout << i;
        }
        cout << "\n";
    }

    return 0;
}

How It Works

1. Prompt and read. Ask for a row count, then store it with cin >> rows.

2. Compute the top letter. For rows = 4, top is 'D' — first row is D.

3. Same countdown core. Only the source of top changes — the print logic matches Example 1.

4. Safer input tip. Unchecked cin leaves rows unset on bad input. Prefer:

Safer input
if (!(cin >> rows) || rows < 1 || rows > 26) {
    cout << "Enter a whole number from 1 to 26.\n";
    return 1;
}

Example 3 — string(repeat, ch)

Build each repeated-letter row in one call — same shape without an explicit inner print loop.

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

int main() {
    int rows = 5;
    char top = (char)('A' + rows - 1);

    for (char ch = top; ch >= 'A'; ch--) {
        int repeat = (top - ch) + 1;
        cout << string(repeat, ch) << "\n";
    }

    return 0;
}

How It Works

1. Map letter to width. repeat = (top - ch) + 1 — one for the top letter, two for the next, and so on.

2. Build the row. string(repeat, ch) creates a string of length repeat filled with ch.

3. Print once. One cout per row replaces the inner letter loop.

Learn the nested-loop version first (Examples 1–2); treat string(n, ch) as a polish shortcut afterward.

Edge Cases & Pitfalls

Check these before calling the solution done.

cout j

Letters change across the row

Printing j instead of i produces reverse runs like Program 7. Use cout << i for a uniform row.

i++

Program 9 by mistake

If the outer loop increments from A, you get A, BB, CCC. Count down from top for this pattern.

\n inside

Column of letters

If cout << "\n" is inside the inner loop, each letter lands on its own line. Call it only after the inner loop.

rows > 26

Past Z

'A' + rows - 1 leaves A–Z when rows > 26. Clamp or reject in interactive programs.

rows = 1

Single A

Output is just A — a good sanity check for the mapping and the break.

cin fail

Check the stream

If cin fails, rows may be unset — always test if (!(cin >> rows)) and prefer 1–26.

Time and Space Complexity

ProgramTimeExtra space
Nested loops + cout (Examples 1–2)O(rows²)O(1)
string(n, ch) (Example 3)O(rows²)O(row width) temporary per row

Total letters printed = 1 + 2 + … + n = n(n+1)/2, which is still quadratic in n.

Key Takeaways

  • Rule: count letters down from the top; grow the repeat count each row.
  • Print the outer letter: inner loop counts; cout << i keeps the row uniform.
  • Vs Program 9: same widths; letters step backward from the top.
  • Complexity: O(n²) time; O(1) extra space for the loop form.

One line: for each letter counting down, print it with growing width, then cout << "\n".

Frequently Asked Questions

Program 9 uses A, BB, CCC, ... (letters increase). Program 10 uses E, DD, CCC, ... (letters decrease) with the same growing repeat counts.
On the 4th row the outer-loop letter is B, and the inner loop runs four times, printing B each time.
j only controls how many times the loop runs. Printing i keeps the row the same letter; printing j would change letters across the row.
With for (j = top; j >= i; j--), when i is near the top the range is short; as i moves toward A the range lengthens, so repeat counts grow 1, 2, 3, …
cout << i stays on the same line. cout << "\n" ends the current line. Letters use cout << i; the row break uses cout << "\n" after the inner loop.
O(n²) where n is the number of rows. Total letter prints equal 1+2+…+n = n(n+1)/2.
Yes. cout << string(repeat, ch) << "\n" prints a full repeated-letter row in one call. Nested loops are better for learning; the string constructor is a handy shortcut later.
After cin >> rows, check failure: if (!(cin >> rows)) handle bad input. Clamp rows between 1 and 26 so you stay within A–Z.

Did you know?

This pattern is the reverse of Program 9: row widths still grow 1, 2, 3, …, but letters run backward (E, then D, then C, …). Print the outer loop letter inside the inner loop so each row stays uniform.

Next: Inverted Repeating Triangle

Same reverse letters with shrinking widths (EEEEE, DDDD, …).

Program 11 tutorial →

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