Repeating-Letter Alphabet Triangle in C

Beginner
⏱️ 8 min read
📚 Updated: Aug 2026
🎯 3 Code Examples
🚀 Live Preview
Nested Loops

What You’ll Learn

Row 1 is one A, row 2 is two Bs, row 3 three Cs, and so on: A, BB, CCC, DDDD, EEEEE. Contrast Program 1, where letters change inside each row. Here, the row letter stays the same and only the count grows. Next up: Program 10 reverses the letter order. Includes a live preview, worked C examples, edge cases, and complexity.

Shape Rule

Repeats grow

One letter per row; count is 1, 2, 3, …

Outer Loop

Row letter

i picks A, B, C, … for each row.

Inner Loop

Count only

Runs 1..row times but always prints i.

vs Program 1

Print i

Same loop bounds; print i not j.

Live Preview

Rows 1–10

Pick a row count and draw A, BB, CCC live.

O(n²)

Complexity

1+2+…+n printed characters total.

Introduction

A repeating-letter alphabet triangle grows like any right-angled triangle, but each row is filled with one repeated character that advances with the row number.

In C the outer loop chooses the letter and the inner loop only decides how many times to write it — print i, never the inner counter.

Why it matters?

It teaches the classic nested-loop lesson: the inner counter can control count while the outer variable controls value — a one-character change from Program 1.

Key Highlights

Outer

i from A to top.

Inner

j from A to i (count).

Print

Always print i.

Output

A, BB, CCC, …

In short: for each letter i from 'A' to top, print i once for each step of j from 'A' to i, then call printf("\n").

📝 Problem & Approach

Given a row count (or fixed top E), print a right-angled triangle where row k repeats the k-th letter of the alphabet k times.

c
// Five rows (top = E)
// A
// BB
// CCC
// DDDD
// EEEEE

Inputs & Outputs

ItemTypeDescription
rows / topint / charNumber of rows; last letter is 'A' + rows - 1 (E for 5).
Printed outputtextGrowing rows of repeated letters A, BB, CCC, …

Minimal workflow

Pseudocode
for i from 'A' to top:          // choose the row letter
    for j from 'A' to i:        // count = row length
        print i                 // NOT j
    print newline

Approach comparison

ApproachIdeaBest for
Char nested loopsOuter i++, inner count, print iMatching this classic sample
Row index + char mathch = (char)('A' + row - 1) then print row timesUser-input versions; clearer count

⚡ Quick Reference

GoalPattern
Fixed A–Efor (char i = 'A'; i <= 'E'; i++)
Repeat countfor (char j = 'A'; j <= i; j++) printf("%c", i);
User rowschar ch = (char)('A' + row - 1); then print ch row times
Stepping lettersSee Program 1 (print j instead)
Reverse lettersSee Program 10 (E, DD, CCC, …)

📋 Prog 1 vs Prog 9 vs Prog 10

Same growing widths — different what you print inside the row.

Program 1
print j

A, AB, ABC — letters step

Program 9
print i

A, BB, CCC — letters repeat

Program 10
print i reverse

E, DD, CCC — reverse order

printf("\n")
break

Ends the row after the repeats

Context

When This Pattern Shows Up

Reach for this when teaching that the inner loop can control count while the outer variable controls the printed value.

  1. After Program 1

    Keep the same loop bounds; change only printing j to printing i.

  2. Repeat-count drills

    Practice decoupling “what to print” from “how many times.”

  3. Bridge to Program 10

    Next keeps repeats but walks the letter backward: E, DD, CCC.

  4. Index-to-char practice

    Map row numbers to letters with 'A' + row - 1.

  5. Not a UI layout tool

    This is a console teaching pattern — not how you build modern app screens.

Key benefit: printing the outer letter inside the inner loop is the cleanest way to build a growing triangle of repeated characters.

🔮 Live Preview

Choose 1–10 rows and draw the repeating-letter alphabet triangle in the browser.

Try 5 (classic A…EEEEE) or 4 (A…DDDD). Max 10 keeps the preview readable.

Live result
Press "Draw pattern".

Examples Gallery

Three complete C programs — fixed A–E, user-chosen row count, and a spaced-letter variant. Click View Output to reveal sample console results.

📚 Getting Started

Print five growing rows of repeated letters from A to E.

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

When i = 'C', the inner loop runs three times and prints C each time → CCC. Printing j instead would produce ABC on that row.

📈 Practical Variant

Let the user choose how many rows to print.

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

For row 4, ch becomes 'D' and the inner loop prints it four times. Cap rows at 26 so ch stays within A–Z.

⚡ Readability Variant

Same triangle with spaces between letters.

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

Loop bounds and the print-i rule are unchanged — only the printed unit becomes i + " ". Trim trailing spaces later if you need a compact line.

🧠 How the Algorithm Prints Rows

1

Outer loop selects the row letter

i runs from 'A' to top. That’s the character printed on the row.

Row character
2

Inner loop controls the repeat count

j runs from 'A' to i, so it executes 1, 2, 3, … times as rows grow.

1..n repeats
3

Print i, not j

Printing i keeps the whole row the same letter. Printing j would change letters across the row (Program 1).

Key idea
4

New line

printf("\n") ends each row before the next letter begins.

Line break
=

Same triangle shape

Total prints are 1+2+…+n for n rows, so time complexity is O(n²).

🔎 Worked Walkthrough — Top = E (5 rows)

Trace each row letter, how many times the inner loop runs, and the printed line.

i (letter)Inner runsPrinted row
A1A
B2BB
C3CCC
D4DDDD
E5EEEEE

Row lengths are 1, 2, 3, 4, 5. Every character on a row matches that row’s letter.

Use Cases

Where this repeating-letter alphabet triangle shows up beyond the homework prompt.

1. Value vs Count Labs

Clearest demo of printing the outer variable inside the inner loop.

Example: change printing i to printing j and compare with Program 1.

2. Repeat Practice

Build intuition for loops that only control iteration count.

Example: rewrite the inner loop as for (int k = 0; k < n; k++).

3. Char Math

Map row indexes to letters with 'A' + row - 1.

Example: scale from 5 to 8 without rewriting loops.

4. String Helpers

Later rewrite as new string(ch, row) once the idea clicks.

Example: same output with one print per row.

5. Complexity Intuition

Triangle sums make O(n²) easy to see.

Example: 15 letters for 5 rows.

6. Series Continuity

Sits between Programs 8 and 10 in the alphabet set.

Example: revisit Program 1.

Pro Tip: say “pick the letter outside, repeat it inside” before coding — that story prevents printing j by habit.

Advantages

Why this pattern earns a spot early in the alphabet-pattern series.

  1. 1. Instant Visual Feedback

    A stepping-letter row (ABC) shows immediately if you printed j.

  2. 2. Tiny Diff from Program 1

    Only the printed variable changes.

  3. 3. Scales Cleanly

    Change the top letter or row count and the whole triangle grows.

  4. 4. Beginner-Friendly

    No padding or diagonal checks — just two loops and one print rule.

Pro Tip: master Program 1 first; this page is mostly “same loops, print the outer letter.”

Usage Tips

Small habits that keep repeating-letter alphabet triangles clean.

  1. 1. Always Print i (or ch)

    Printing j turns this into Program 1.

  2. 2. Let the Inner Loop Only Count

    Do not increment the character inside the inner loop.

  3. 3. Cap Rows at 26

    Keep the row letter inside A–Z when taking user input.

  4. 4. Check scanf

    Validate the row count and check scanf’s return value.

  5. 5. Compute the Letter from the Row

    Use ch = (char)('A' + row - 1) when working with integer row indexes.

Pro Tip: if you see A, AB, ABC, you printed j — switch back to printf("%c", i).

Common Pitfalls

Mistakes that commonly break repeating-letter alphabet triangles.

  1. 1. Printing j Instead of i

    Produces Program 1 (A, AB, ABC) instead of A, BB, CCC.

    → Use printf("%c", i) (or ch) inside the inner loop.

  2. 2. Incrementing the Letter Inside the Inner Loop

    Changes the character mid-row and breaks the uniform look.

    → Keep the letter fixed for the whole row.

  3. 3. Wrong Letter Formula

    Using 'A' + row without - 1 starts at B.

    → Use ch = (char)('A' + row - 1).

  4. 4. Unchecked scanf

    Empty or non-numeric input leaves rows uninitialized.

    → Check scanf’s return value and validate range.

  5. 5. Forgetting printf("\n")

    All letters dump onto one line.

    → Call printf("\n") after each inner loop.

Edge Cases

Check these inputs before calling the solution done.

rows = 1

Single letter

Output is just A.

rows = 5

Classic sample

A through EEEEE (Example 1).

rows = 4

Smaller triangle

Ends at DDDD (Example 2).

rows > 26

Past Z

Cap or reject — the row letter leaves the alphabet.

Bad input

Empty / non-numeric

Check scanf’s return value.

Lowercase

a, bb, ccc

Swap 'A' for 'a' as the base.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Flip to Program 1

  • Change only printing i to printing j
  • Confirm you get A, AB, ABC

2. Reverse the letters

  • Start the outer letter at E and count down
  • Continue to Program 10

3. Scale to 8 rows

  • Use the input version
  • Check the last row is HHHHHHHH

4. One print per row

  • Rewrite with new string(ch, row)
  • Confirm the output matches Example 2

Notes

  • Outer picks the letter. Inner only decides how many times to print it.
  • Printing i (not j) is what keeps each row uniform.
  • Row lengths are 1, 2, …, n — same geometry as Program 1.
  • Next up: Alphabet Pattern 10 reverses the letter order while keeping repeats.

Quick Takeaway: choose the row letter in the outer loop, then print that letter once per inner iteration — that alone builds A, BB, CCC, …

⏱️ Time and Space Complexity

ProgramTimeExtra space
Inline / input (Examples 1–2)O(n²)O(1)
Spaced letters (Example 3)O(n²)O(1)

For n rows you print 1+2+…+n = n(n+1)/2 characters, so total work is O(n²).

Wrap Up

🎉 Conclusion

The repeating-letter alphabet triangle is Program 1 with a different print rule: the outer loop picks the letter, and the inner loop only repeats it. Master the classic A…EEEEE sample, then try user input and the spaced rewrite.

Practice the three examples above, then continue to Alphabet Pattern 10.

Outer i from A to top, inner count from A to i, print i each time, then break each line.

💡 Best Practices

✅ Do

  • Print the outer letter (i or ch) inside the inner loop
  • Use the inner loop only for the repeat count
  • Compute ch = (char)('A' + row - 1) for integer row indexes
  • Cap user row counts at 26
  • State O(n²) when asked about complexity

❌ Don’t

  • Print j when you want A, BB, CCC
  • Change the letter inside the inner loop
  • Forget the - 1 in the letter formula
  • Skip validating row-count input
  • Call printf("\n") inside the letter loop

Key Takeaways

Knowledge Unlocked

Five things to remember about this alphabet pattern

Print the repeating-letter alphabet triangle the beginner-friendly way.

5
Core concepts
= 02

Print

Print i, not j

Code
1 03

Inner

Controls count only

Shape
R 04

vs Prog 1

Same loops, different print

Compare
O 05

Complexity

O(n²) time

Analysis

❓ 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).
Yes. You can compute it from the row index: ch = (char)('A' + row - 1), then print ch row times.
O(n²) for n rows, because total printed characters are n(n+1)/2.
Check scanf("%d", &rows) == 1, require n ≥ 1, and cap at 26 so the row letter stays within A–Z.
Yes. Use 'a' as the base: ch = (char)('a' + row - 1), or loop i from 'a' with the same print-i rule.

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.

Explore More C Alphabet Patterns!

A one-line change inside the inner loop can switch between repeating letters and stepping letters.

All Alphabet Patterns →

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