C++ Reverse Alphabet Triangle Pattern (Decreasing)

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

What Is This Pattern?

A reverse decreasing alphabet triangle prints each row backward down to A, while the starting letter moves one step closer to A on every line.

Remember
Rule: on row with start i, print i..A (descending)

EDCBA
DCBA
CBA
BA
A         ← 5 rows (top = 'E')

Same shrinking widths as Program 6, but letters run the other way. Compare with Program 8, which always starts at the top letter and shortens the tail instead.

How to Solve It

Two ways to emit the same shape — classic nested char loops, or spaced letters for readability.

MethodIdeaBest for
Nested char loopsOuter i-- from top; inner prints i..ALearning, interviews, exams
Spaced lettersSame bounds; print j << " "Clearer console demos once loops click

Pseudocode

Pseudocode
top = 'A' + rows - 1
for i from top down to 'A':
    for j from i down to 'A':
        print j (no newline)
    print newline

Cheat sheet

GoalPattern
Top letterchar top = char('A' + rows - 1);
Shrink startfor (char i = top; i >= 'A'; i--)
Print i..Afor (char j = i; j >= 'A'; j--) cout << j;
End the rowcout << "\n";
vs Program 6Program 6: forward i..end; this page: reverse i..A
Letter totaln + (n−1) + … + 1 = n(n+1)/2

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 finishes a row

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

Live Preview

Change the row count and the reverse triangle updates instantly — every row still ends on A.

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

Live result 5 rows · top E · 15 letters
EDCBA
DCBA
CBA
BA
A

Worked Walkthrough — Top = E (5 rows)

Trace each start letter i and the descending run down to A.

i (start)Inner rangePrinted rowLetters
EE..AEDCBA5
DD..ADCBA4
CC..ACBA3
BB..ABA2
AA..AA1

Total letter prints: 5 + 4 + 3 + 2 + 1 = 15 = 5×6/2. The right edge is always A; that triangular sum is why time is O(n²).

C++ Programs

Three complete programs: fixed A–E, row-count input, and a spaced-letter variant. Use View Output to reveal sample results.

Example 1 — Fixed Top E

Hard-coded height — outer loop lowers the start; inner loop always counts down to A.

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

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

    return 0;
}

How It Works

1. Outer loop picks the start. i runs from 'E' down to 'A' — each row begins one letter earlier.

2. Inner loop prints down to A. For each i, j runs from i down to 'A', so every row ends with A.

3. Break the line. cout << "\n" after the inner loop starts the next (shorter) row.

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

Example 2 — Row Count Input

Read the number of rows and compute top = 'A' + rows - 1. Prefer validating cin in real apps.

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

int main()
{
    int rows;
    cout << "Enter the number of rows: ";
    cin >> rows;

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

    return 0;
}

How It Works

1. Scale with rows. For 4 rows, top becomes 'D'. Cap rows at 26 so top stays within A–Z.

2. Same nested-loop core. Only the source of top changes — the print logic matches Example 1.

3. Safer input tip. 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 bounds — print a trailing space after each letter so columns are easier to scan.

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

int main()
{
    char top = 'E';

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

    return 0;
}

How It Works

1. Bounds unchanged. Outer still lowers i; inner still walks i..A downward.

2. Only the printed unit changes. Each cell becomes j + " ". Trim trailing spaces later if you need a compact line.

Edge Cases & Pitfalls

Check these before calling the solution done.

j++

Forward instead of reverse

If the inner loop increments toward the end letter, you get Program 6. Keep j-- down to 'A' for reverse rows.

\n early

Column of letters

If cout << "\n" is inside the inner loop, each letter lands on its own line. Print letters without a newline; end the row only after the inner loop.

Fixed start

Confused with Program 8

Program 8 always starts at the top letter and shortens the stop. This pattern changes the first letter each row.

rows = 1

Single A

Output is just A on one line — a good sanity check.

rows > 26

Beyond Z

Cap or reject — top leaves the alphabet. Keep rows in 1…26 for A–Z demos.

Bad cin

Validate rows

Check cin >> rows, require a positive whole number, and clamp to 26 before building top.

Time and Space Complexity

ProgramTimeExtra space
Nested loops (Examples 1–2)O(n²)O(1)
Spaced letters (Example 3)O(n²)O(1)

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

Key Takeaways

  • Rule: start moves toward A each row; every row prints descending to A.
  • Two loops: both decrement — outer for start, inner for i..A.
  • Break the row: cout << "\n" only after the inner loop.
  • Complexity: O(n²) time; O(1) extra space.

One line: for each start i from top down to A, print i..A descending, then a newline.

Frequently Asked Questions

The outer loop picks the starting letter (E, then D, then C…). The inner loop prints from that start down to A, so the first line is EDCBA and each next line drops the previous leftmost letter.
The outer loop decreases the starting letter each row, and the inner loop decreases letters within that row down to A. That matches the reverse-alphabet output.
Program 6 prints forward suffixes ending at E (ABCDE, BCDE, …). This pattern prints reverse runs ending at A (EDCBA, DCBA, …). Same shrinking widths; opposite letter direction.
Program 8 always starts each row at E and shortens the tail (EDCBA, EDCB, EDC). Program 7 changes the first letter each row (E, then D, then C…).
Because the inner loop runs until j == 'A', so the final character printed on each row is always A.
O(n²) for n rows, because total printed characters are n+(n−1)+…+1 = n(n+1)/2.
Yes. Read rows from cin, set top = char('A' + rows - 1), then loop i from top down to 'A' and print j from i down to 'A'.
After cin >> rows, check failure, require n ≥ 1, and cap at 26 so the top letter stays within A–Z.

Did you know?

This triangle prints reverse letters and shrinks each row: EDCBA, DCBA, CBA, BA, A. Both loops run backward so letters move toward 'A' on every line.

Next: Reverse Fixed Start

Always begin at the top letter and shorten the descending tail — EDCBA, EDCB, EDC…

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