C++ Repeating Alphabet Triangle Pattern

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

What Is This Pattern?

A repeating alphabet triangle grows by one character each row, but every character on that row is the same letter — the letter advances with the row.

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

A
BB
CCC
DDDD
EEEEE     ← 5 rows

Unlike Program 1 (A, AB, ABC), letters do not step across the row — you print the outer loop letter inside the inner loop. The reverse twin is Program 10 (E, DD, CCC, …).

How to Solve It

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

MethodIdeaBest for
Nested char loopsOuter = letter; inner = growing width; print outer letterLearning, interviews, exams
string(row, ch)Build a whole repeated-letter row in one callShorter demos once loops click

Pseudocode

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

Cheat sheet

GoalPattern
Advance letterfor (char i = 'A'; i <= last; i++)
Grow widthfor (char j = 'A'; j <= i; j++)
Uniform rowcout << i; — print i, not j
End the rowcout << "\n";
Letter from row indexchar ch = char('A' + row - 1);
One-line shortcutcout << string(row, ch) << "\n";
Reverse twinProgram 10 (E, DD, CCC, …)

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

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 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
A
BB
CCC
DDDD
EEEEE

Worked Walkthrough — rows = 4

Trace each outer-loop letter as i advances from 'A' to 'D'.

Letter iInner runsPrinted rowRepeats
'A'1A1
'B'2BB2
'C'3CCC3
'D'4DDDD4

Total letter prints: 1 + 2 + 3 + 4 = 10 = 4×5/2 — same triangular count as Program 1.

C++ Programs

Three complete programs: fixed last letter, cin input, and a string(n, ch) shortcut. Use View Output to reveal sample results.

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

Hard-coded last letter — outer loop picks the letter; inner loop only controls the repeat count.

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

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

    return 0;
}

How It Works

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

2. Inner loop only counts. j runs from 'A' to i, so the width grows 1, 2, 3, …

3. Print i, not j. That keeps every character on the row the same. Printing j would rebuild Program 1.

When i = 'C' the inner loop runs three times and you get CCC.

Example 2 — User Input Version

Read the row count at runtime. Prefer validating cin and clamping to 26 (shown in the tip below).

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

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

    for (int row = 1; row <= rows; row++)
    {
        char ch = char('A' + row - 1);
        for (int j = 1; j <= row; j++)
            cout << ch;
        cout << "\n";
    }

    return 0;
}

How It Works

1. Prompt and read. Ask for a row count, then store it in rows.

2. Map row index to a letter. ch = char('A' + row - 1) — for row = 3, ch is 'C'.

3. Repeat ch exactly row times. Same uniform-row idea as Example 1, expressed with integer bounds.

4. 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 — string(row, ch)

Build each repeated-letter row in one call — same shape, no explicit inner letter loop.

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

int main()
{
    int rows = 5;

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

    return 0;
}

How It Works

1. Pick the letter from the row index. Same mapping as Example 2: row 1 → A, row 2 → B, and so on.

2. Fill a string of length row. string(row, ch) creates a string filled with ch — e.g. string(3, 'C') is CCC.

3. Learn loops first. Use Examples 1–2 when you need to show nested bounds; treat this as a polish shortcut afterward.

Edge Cases & Pitfalls

Check these before calling the solution done.

cout << j

Program 1 by mistake

Printing j instead of i produces A, AB, ABC. Use cout << i (or ch) for a uniform row.

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

Off-by-one

Wrong letter mapping

Use char('A' + row - 1). Forgetting - 1 shifts every letter one step forward.

rows > 26

Past Z

'A' + row - 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.

Bad cin

Validate rows

Check cin >> rows and require 1–26 before the outer loop.

Time and Space Complexity

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

Total letters = 1 + 2 + … + n = n(n + 1)/2 — quadratic in n. Same totals as Program 1.

Key Takeaways

  • Rule: outer loop picks the letter; inner loop only sets how many times to print it.
  • Print i, not j: that single choice separates this pattern from Program 1.
  • Break the row: call cout << "\n" only after the inner loop.
  • Complexity: O(n²) time from the triangular letter count; O(1) extra space for nested loops.

One line: for each letter i, print i exactly as many times as the row width, then end the line.

Frequently Asked Questions

Because the inner loop prints the outer-loop character (i) every time. The inner counter only controls how many times to print, not which character to print.
Then letters would change across the row (A, AB, ABC…), which is Program 1 — not a repeating-letter triangle.
On the third row the row letter is C, and the inner loop runs three times, printing C each time.
Program 1 prints stepping letters across each row (A, AB, ABC). This pattern keeps one letter per row and only grows the repeat count (A, BB, CCC).
Program 10 uses the same growing widths but letters count downward (E, DD, CCC…). This pattern counts upward (A, BB, CCC…).
Printing a character stays on the same line. Printing a newline ends the current line. Letters use cout without a newline; the row break uses cout << "\n" after the inner loop.
O(n²) for n rows, because total printed characters are n(n+1)/2.
Yes. cout << string(row, ch) << "\n" prints a full repeated-letter row in one call. Nested loops are better for learning; the string fill constructor is a handy shortcut later.

Did you know?

Each row prints the same letter repeatedly: row 1 prints A once, row 2 prints B twice, row 3 prints C three times. Print the outer loop letter inside the inner loop so the row stays uniform. The reverse twin is Program 10.

Next: Reverse Repeating Triangle

Same growing widths, letters counting down from E.

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