Repeating-Letter Alphabet Triangle in C

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:
A
BB
CCC
DDDD
EEEEEComplete C Program (Fixed Rows)
After each row, ch++ advances to the next letter. The inner loop only controls how many copies, not which letter.
#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
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.
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.
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.
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, …).
Triangle of repeats
Total characters = 1 + 2 + … + n = n(n+1)/2 for n rows. Nested loops over row length give O(n²) time.
Variation — User Input Version
Use scanf for rows. For large rows, plan what happens after 'Z' (or cap rows at 26 for A–Z).
#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 carryingchacross iterations - Inverted repeat triangle: begin at
'E'and usech--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
rowswithout thinking about passing'Z' - Mixing this with program 1’s per-cell
ch++logic by accident
Key Takeaways
Inner loop count = row number; inner body always prints the same ch.
Advance ch once per row, after the inner loop.
O(n²) prints for n rows.
Good bridge between star triangles and alphabet patterns.
❓ Frequently Asked Questions
printf("%c", ch) without updating ch, so every column on that row shows the same value.Explore More C Alphabet Patterns!
Changing when you update ch completely changes whether a row repeats or runs through the alphabet.
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.
12 people found this page helpful
