C++ Alphabet Triangle Pattern (Reverse Order)

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

What Is This Pattern?

A reverse-order alphabet triangle grows the peak letter on the left (A, B, C, …) while each row prints letters backward down to A:

Remember
Rule: on row with peak i, print i down to A

A
BA
CBA
DCBA
EDCBA     ← 5 rows

Unlike Program 1 (forward along each row) and Program 3 (reverse start, forward to a fixed top), this pattern ends every row at A. Two nested char loops — outer raises the peak, inner counts down — then cout << "\n" ends the line.

How to Solve It

Raise the peak on the outer loop; count down to A on the inner loop. Start compact, then optionally space the letters.

MethodIdeaBest for
Compact lettersOuter = peak; inner = peak..A via cout << jLearning, interviews, exams
Spaced letterscout << j << " "Readable columns in demos

Pseudocode

Pseudocode
for peak from 'A' to lastLetter:   // lastLetter depends on rows
    for ch from peak down to 'A':
        print ch (no newline)
    print newline

Cheat sheet

GoalPattern
Raise the peakfor (char i = 'A'; i <= last; i++)
Print i..Afor (char j = i; j >= 'A'; j--) cout << j;
End the rowcout << "\n";
Last letter from rowslast = (char)('A' + rows - 1);
Spaced democout << j << " ";
Invert laterShrink the end letter each row → Program 5

Printing Letters vs Starting a New Line

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

Print characters without a newline, then end the row once. cout << endl also ends the line (and flushes); "\n" is enough for these demos.

Live Preview

Change the row count and the reverse-order 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
A
BA
CBA
DCBA
EDCBA

Worked Walkthrough — rows = 4

Trace each outer-loop peak and count how many times the inner loop prints.

Peak iInner jPrinted rowLetters
'A'A..AA1
'B'B..ABA2
'C'C..ACBA3
'D'D..ADCBA4

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

C++ Programs

Three complete programs: fixed peak through E, cin input, and a spaced-letter variant. Use View Output to reveal sample results.

Example 1 — Fixed through 'E'

Hard-coded peak — outer loop raises the start letter; inner loop prints down to 'A' (5 rows).

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

int main() {
    char i, j;

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

    return 0;
}

How It Works

1. Outer loop raises the peak. i runs from 'A' to 'E' — one row per peak letter.

2. Inner loop counts down to A. For each i, j runs from i down to 'A', so the row is i..A.

3. Print letters, then break the line. cout << j stays on the row; cout << "\n" after the inner loop starts the next row.

When i = 'A' you get A; when i = 'C' you get CBA; up through EDCBA.

Example 2 — User Input Version

Read the row count at runtime with cin. Always check failure in real apps (shown in the tip below).

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

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

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

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

    return 0;
}

How It Works

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

2. Map rows to a peak letter. last = (char)('A' + rows - 1) — for rows = 4, last is 'D'.

3. Same nested-loop core. Only the source of last 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 — Spaced letters

Same shape with cout << j << " " so letters sit in readable columns.

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

int main() {
    char i, j;

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

    return 0;
}

How It Works

1. Same loops. Peak still grows; letters still count down to 'A'.

2. Only the print format changes. Appending " " adds a trailing space after each letter.

3. Learn compact first. Use Examples 1–2 when matching exam samples; add spaces when you want clearer columns.

Edge Cases & Pitfalls

Check these before calling the solution done.

j++

Wrong direction

Using j++ from i prints forward past i — you get Program 1’s shape, not BA/CBA. Count down with j-- to 'A'.

Stop early

Missing final A

The condition must be j >= 'A' (inclusive). Stopping at j > 'A' drops the trailing A on every row.

\n inside

Column of letters

If cout << "\n" is inside the inner loop, each letter lands on its own line. End the row only after the countdown finishes.

No newline

One endless line

Omitting the row break glues every letter onto a single line.

rows > 26

Past Z

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

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–3)O(rows²)O(1)

Total letters printed = 1 + 2 + … + n = n(n+1)/2, which is still quadratic in n. Extra memory stays constant aside from the output stream.

Key Takeaways

  • Rule: row with peak i prints i down through A.
  • Two loops: outer = peak letter, inner = peak..A with cout << j.
  • Break the row: call cout << "\n" only after the inner loop.
  • Complexity: O(n²) time from the triangular letter count; O(1) extra space.

One line: for each peak i, print i down to A with cout, then cout << "\n".

Frequently Asked Questions

The outer loop picks the peak letter on each row (A, then B, then C, …). The inner loop starts at that peak and counts down to A, so each row reads backward.
Because the inner loop always runs until j == 'A', so the last printed character on every row is A.
cout << j stays on the same line. cout << "\n" ends the current line. Letters use cout << j; the row break uses cout << "\n" after the inner loop.
Program 1 prints forward along each row (A, AB, ABC). This pattern prints backward down to A (A, BA, CBA) while the left edge still grows A, B, C, …
Program 3 starts earlier each row but prints forward to a fixed top (E, DE, CDE). This pattern starts later each row and prints backward to a fixed A.
O(n²) where n is the number of rows. Total letter prints equal 1+2+…+n = n(n+1)/2.
After cin >> rows, check failure: if (!(cin >> rows)) handle bad input. Clamp rows between 1 and 26 so you stay within A–Z.
Yes. Start from 'a' and loop the same way: outer i from 'a' up, inner j from i down to 'a'.

Did you know?

Each row’s peak letter grows forward (A, B, C, …), but letters print backward down to A. For 5 rows you get A, BA, CBA, DCBA, EDCBA — the right edge stays A.

Next: Inverted Alphabet Triangle

Shrink the end letter each row while still printing forward from A.

Program 5 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