Repeating-Letter Alphabet Triangle in C

Beginner
⏱️ 5 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
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.

The nested loop shape matches program 1, but the inner body prints the same ch each time instead of stepping through the alphabet inside the row.

⭐ Pattern Output

For 5 rows:

Output
A
BB
CCC
DDDD
EEEEE
1

Complete C Program (Fixed Rows)

After each row, ch++ advances to the next letter. The inner loop only controls how many copies, not which letter.

c
#include <stdio.h>

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

    for (i = 1; i <= 5; ++i) {
        for (j = 1; j <= i; ++j) {
            printf("%c", ch);
        }
        printf("\n");
        ch++;
    }

    return 0;
}

🧠 How It Works

1

ch = 'A'

One variable holds the repeated letter for the whole row. Unlike a growing triangle that prints A, AB, …, every character on a row is the same before you move on.

Setup
2

Outer loop: row index i

for (i = 1; i <= 5; ++i) counts rows. When i is 3, the inner loop runs three times, so row three has three copies of the current ch.

Width
3

Inner loop: print ch unchanged

printf("%c", ch) only reads ch. The inner index j just controls how many times you print, so the row stays one solid letter.

Repeat
4

New line, then ch++

After the inner loop, printf("\n") starts the next row. ch++ bumps the ASCII code so the next row uses the next letter (B, C, …).

Next letter
=

Triangle of repeats

Total characters = 1 + 2 + … + n = n(n+1)/2 for n rows. Nested loops over row length give O(n²) time.

2

Variation — User Input Version

Use scanf for rows. For large rows, plan what happens after 'Z' (or cap rows at 26 for A–Z).

c
#include <stdio.h>

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

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

    for (i = 1; i <= rows; ++i) {
        for (j = 1; j <= i; ++j) {
            printf("%c", ch);
        }
        printf("\n");
        ch++;
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Start at 'a' for lowercase repeats
  • Equivalent row letter: ch = (char)('A' + i - 1) each row without carrying ch across iterations
  • Inverted repeat triangle: begin at 'E' and use ch-- after each row with outer loop shrinking width
  • Pad with spaces to center the triangle

Avoid

  • ch++ inside the inner loop unless you want AB, CD, EF, … style stepping
  • Unbounded rows without thinking about passing 'Z'
  • Mixing this with program 1’s per-cell ch++ logic by accident

Key Takeaways

1

Inner loop count = row number; inner body always prints the same ch.

2

Advance ch once per row, after the inner loop.

3

O(n²) prints for n rows.

4

Good bridge between star triangles and alphabet patterns.

❓ Frequently Asked Questions

The inner loop calls printf("%c", ch) without updating ch, so every column on that row shows the same value.
After the inner loop and newline, so the whole row shares one letter, then the next row moves to the next character.
Letters continue in ASCII order ([, \\, ], …). Usually you cap rows or wrap modulo 26 for display.
O(n²) for n rows.

Explore More C Alphabet Patterns!

Changing when you update ch completely changes whether a row repeats or runs through the alphabet.

All Alphabet Patterns →
Did you know?

You can set ch = (char)('A' + i - 1) at the top of each outer iteration instead of ch++—same letters, sometimes easier to reason about for arbitrary rows.

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