C Repeating Alphabet Triangle Pattern

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

What Is This Pattern?

A repeating alphabet triangle prints one letter per row and repeats it as many times as the row number — classic five-row sample: A, BB, CCC, DDDD, EEEEE.

Remember
Rule: outer picks letter i; inner only counts — always print i

A
BB
CCC
DDDD
EEEEE     ← 5 rows (top = E)

Unlike Program 1 (letters change inside the row: A, AB, ABC), here the row letter stays fixed and only the repeat count grows.

How to Solve It

Outer loop picks the row letter; inner loop runs the right number of times but always prints that letter.

MethodIdeaBest for
Char rangeOuter i from A..top; inner j from A..i; print iLearning, interviews, fixed demos
Row indexch = 'A' + row - 1; print ch row timesUser input for height

Pseudocode

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

Cheat sheet

GoalPattern
Pick the row letterfor (char i = 'A'; i <= top; i++)
Repeat i (A..i times)for (char j = 'A'; j <= i; j++) printf("%c", i);
Letter from row indexch = (char)('A' + row - 1);
Spaced lettersprintf("%c ", i);
End the rowprintf("\n");
A–Z-safe heightClamp rows to 1–26

Printing Letters vs Starting a New Line

APIEffectUse for
printf("%c", i)Stays on the same lineEach repeated letter on the row
printf("\n")Ends the current lineAfter the inner loop

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

Live Preview

Change the row count and the repeating alphabet triangle updates instantly — including last letter and letter totals.

Whole numbers from 1 to 10. Last letter is A + rows - 1; total letters equal n(n+1)/2.

Live result 5 rows · last E · 15 letters
A
BB
CCC
DDDD
EEEEE

Worked Walkthrough — top = 'E'

Trace each row letter i and how many times the inner loop prints it.

iInner runsPrinted rowCount
A1×A1
B2×BB2
C3×CCC3
D4×DDDD4
E5×EEEEE5

Total letters: 1 + 2 + 3 + 4 + 5 = 15 = n(n+1)/2. Printing j instead of i on row C would give ABC, not CCC.

C Programs

Three complete programs: fixed top E, row-count input, and spaced letters. Use View Output to reveal sample results.

Example 1 — Fixed Top E

The inner loop runs the correct number of times, but always prints i (the row letter).

C
#include <stdio.h>

int main() {
    char i, j;

    for (i = 'A'; i <= 'E'; i++) {
        for (j = 'A'; j <= i; j++) {
            printf("%c", i);
        }
        printf("\n");
    }

    return 0;
}

How It Works

1. Outer loop picks the letter. i walks A, B, C, D, E — one letter per row.

2. Inner loop only counts. From 'A' to i sets the width. Always print i, not j.

3. Break the line. printf("\n") after the inner loop starts the next longer row.

Example 2 — Row Count Input

Compute the row letter from the row number. Check scanf in real apps, and keep rows within 26 for A–Z.

C
#include <stdio.h>

int main() {
    int rows, row, col;
    char ch;

    printf("Enter the number of rows: ");
    scanf("%d", &rows);

    for (row = 1; row <= rows; row++) {
        ch = (char)('A' + row - 1);
        for (col = 1; col <= row; col++) {
            printf("%c", ch);
        }
        printf("\n");
    }

    return 0;
}

How It Works

1. Map row → letter. For row 4, ch becomes 'D'.

2. Print ch row times. The inner loop uses a numeric counter; the printed character never changes mid-row.

3. Safer input tip. Check scanf and stay within A–Z:

Safer input
if (scanf("%d", &rows) != 1 || rows < 1 || rows > 26) {
    printf("Enter a row count from 1 to 26.\n");
    return 1;
}

Example 3 — Spaced Letters

Print a trailing space after each letter so columns are easier to scan.

C
#include <stdio.h>

int main() {
    char i, j;

    for (i = 'A'; i <= 'E'; i++) {
        for (j = 'A'; j <= i; j++) {
            printf("%c ", i);
        }
        printf("\n");
    }

    return 0;
}

How It Works

1. Same bounds. Outer and inner loops match Example 1 — only the printed unit changes.

2. Letter plus space. printf("%c ", i) makes columns easier to read at a glance.

3. Compact tip. Trim trailing spaces later if you need a tight line without a final space.

Edge Cases & Pitfalls

Check these before calling the solution done.

print j

Wrong pattern

Printing j instead of i builds Program 1 (A, AB, ABC). Always print the outer letter.

Fixed width

Rectangle

If the inner loop always runs to the same end (for example always to E), every row has the same length.

Missing \\n

One long line

Call printf("\n") after each inner loop. Without it, every letter lands on one line.

rows = 1

Single A

Output is just A — a good sanity check.

Past Z

Clamp to 26

More than 26 rows walks the row letter past Z. Cap or reject the input.

scanf fail

Unchecked input

Always check scanf("%d", &rows) == 1 so bad input does not leave rows uninitialized.

Time and Space Complexity

ProgramTimeExtra space
Fixed / input / spaced formsO(n²)O(1)

Total letters printed = 1 + 2 + … + n = n(n+1)/2, which is quadratic in the number of rows.

Key Takeaways

  • Print the outer letter: inner loop counts; printf("%c", i) keeps the row uniform.
  • Width grows with i: row letter A runs once, B twice, C three times, and so on.
  • Vs Program 1: same loop shape; printing j changes letters mid-row.
  • Complexity: O(n²) time; O(1) extra space.

One line: for each letter i, print i as many times as the row width, then printf("\n").

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 a different alphabet pattern like Program 1.
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 run backward (E, DD, CCC, …).
O(n²) for n rows, because total printed characters are n(n+1)/2.
Yes. Compute ch = (char)('A' + row - 1), then print ch row times.
Check scanf("%d", &rows) == 1, require n ≥ 1, and cap at 26 so the row letter stays within A–Z.

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, and so on. The key is to print the outer loop letter inside the inner loop.

Next: Reverse Repeating Triangle

Same growing widths, letters counting down (E, DD, CCC, …).

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