C++ Repeating Alphabet Pattern (Inverted Forward)

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

What Is This Pattern?

An inverted forward repeating alphabet triangle shrinks in width each row while the letter advances: row 1 is all As, row 2 all Bs, and so on.

Remember
Rule: width i from rows down to 1;
      print ch exactly i times, then ch++

AAAAA
BBBB
CCC
DD
E         ← 5 rows (start ch = 'A')

Same inverted widths as Program 11, but letters count up with ch++ instead of down. Print ch in the inner loop, then ch++ after each row so every line stays uniform.

How to Solve It

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

MethodIdeaBest for
Nested loops + ch++Outer = shrinking width; print ch, then incrementLearning, interviews, exams
string(repeat, ch)One call builds a full repeated-letter rowShort demos once loops click

Pseudocode

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

Cheat sheet

GoalPattern
Shrink widthfor (int i = rows; i >= 1; i--)
Repeat letterfor (int j = 1; j <= i; j++) cout << ch;
Uniform rowPrint ch, not j
End row + step lettercout << "\n"; ch++;
Start letterch = 'A';
string shortcutcout << string(repeat, ch) << "\n";
Countdown twinProgram 11 (EEEEE, DDDD, …)

Printing Letters vs Starting a New Line

APIEffectUse for
cout << chStays on the same lineEach letter on the row
cout << "\n"Ends the current lineAfter the inner loop (before ch++)

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

Live Preview

Change the height and the inverted forward triangle updates instantly — including the letter total.

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

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

Worked Walkthrough — rows = 5, start ch = 'A'

Trace each outer-loop width i and the letter printed on that row.

i (width)chPrinted rowThen
5'A'AAAAAch++ → 'B'
4'B'BBBBch++ → 'C'
3'C'CCCch++ → 'D'
2'D'DDch++ → 'E'
1'E'Edone

Total letter prints: 5 + 4 + 3 + 2 + 1 = 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 'A' up through 'E'

Hard-coded height — outer width shrinks; print ch, then ch++ after each row.

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

int main() {
    int i, j;
    char ch = 'A';

    for (i = 5; i >= 1; i--) {
        for (j = 1; j <= i; j++) {
            cout << ch;
        }
        cout << "\n";
        ch++;
    }

    return 0;
}

How It Works

1. Start at A. ch = 'A' and i = 5 mean the first row is five As.

2. Outer loop shrinks the width. i runs from 5 down to 1.

3. Inner loop prints ch. j runs from 1 to i; each time prints the current letter (not j).

4. Break the line, then step the letter. cout << "\n" ends the row; ch++ prepares B, C, … for the next shorter row.

Example 2 — User Input Version

Keep ch = 'A'; loop i from rows down to 1. Check cin in real apps.

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

int main() {
    int rows, i, j;
    char ch = 'A';

    cout << "Enter the number of rows: ";
    cin >> rows;

    for (i = rows; i >= 1; i--) {
        for (j = 1; j <= i; j++) {
            cout << ch;
        }
        cout << "\n";
        ch++;
    }

    return 0;
}

How It Works

1. Prompt and read. Ask for a row count with cin >> rows.

2. Always start at A. For rows = 4, the first row is AAAA, then BBB, up to a single D.

3. Same shrink core. Only the source of rows changes — the print logic matches Example 1.

4. Safer input tip. Unchecked cin can leave rows unset. 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;

    for (int row = 0; row < rows; row++) {
        char ch = (char)('A' + row);
        int repeat = rows - row;
        cout << string(repeat, ch) << "\n";
    }

    return 0;
}

How It Works

1. Map row to letter and width. Row 0 → A × 5; row 1 → B × 4; 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

Stepping letters on a row

If you print j instead of ch, the row is no longer uniform. Always print ch.

ch++ inside

Letters change mid-row

Put ch++ after the inner loop and newline. Incrementing inside the letter loop steps characters across the row.

ch-- by mistake

Program 11 shape

Using ch-- from a top letter reprints Program 11. Keep ch = 'A' and ch++ for this forward pattern.

\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 all repeats.

rows = 1

Single A

Output is just A — a good sanity check.

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 (Examples 1–2)O(rows²)O(1)
string(n, ch) (Example 3)O(rows²)O(row width) temporary per row

Total letters = n + (n - 1) + … + 1 = n(n + 1)/2 — still quadratic in n. Same totals as Program 11; only the letter direction differs.

Key Takeaways

  • Rule: shrink width i; print ch exactly i times; then ch++.
  • Twin of Program 11: same widths — letters advance A→E instead of counting down.
  • Break then step: cout << "\n" first, then ch++ for the next shorter row.
  • Complexity: O(n²) time; O(1) extra space for the loop form.

One line: start at 'A'; for each shrinking width, print ch that many times, then cout << "\n" and ch++.

Frequently Asked Questions

Program 11 prints EEEEE, DDDD, ... (letters step down with ch--). Program 12 prints AAAAA, BBBB, ... (letters step up with ch++) with the same inverted widths 5..1.
i starts at 5 so the first inner loop runs five times while ch is A. After the row, ch becomes B and i is 4, so the next line prints B four times.
So every column on a row shows the same letter. Incrementing inside the inner loop would step letters across the row.
j only controls how many times the loop runs. Printing ch keeps the entire row the same letter; printing j would step letters across the row.
cout << ch stays on the same line. cout << "\n" ends the current line. Letters use cout << ch; the row break uses cout << "\n" after the inner loop.
O(n²) where n is the number of rows. Total letter prints equal n+(n-1)+…+1 = 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. Keep ch = 'A' and loop i from rows down to 1 with ch++ after each row. Clamp to 26 for A–Z demos.

Did you know?

This is the forward-letter twin of Program 11: same inverted widths (5…1), but letters advance A→E with ch++ instead of stepping down. Print ch in the inner loop, then ch++ after each row so every line stays uniform.

Next: Sequential Alphabet Triangle

Letters keep advancing across rows — A, then BC, then DEF, and so on.

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