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.
Approach
How to Solve It
Outer loop picks the row letter; inner loop runs the right number of times but always prints that letter.
Method
Idea
Best for
Char range
Outer i from A..top; inner j from A..i; print i
Learning, interviews, fixed demos
Row index
ch = 'A' + row - 1; print chrow times
User 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
Goal
Pattern
Pick the row letter
for (char i = 'A'; i <= top; i++)
Repeat i (A..i times)
for (char j = 'A'; j <= i; j++) printf("%c", i);
Letter from row index
ch = (char)('A' + row - 1);
Spaced letters
printf("%c ", i);
End the row
printf("\n");
A–Z-safe height
Clamp rows to 1–26
Printing Letters vs Starting a New Line
API
Effect
Use for
printf("%c", i)
Stays on the same line
Each repeated letter on the row
printf("\n")
Ends the current line
After the inner loop
Print characters without a newline, then end the row once.
Try it
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 result5 rows · last E · 15 letters
A
BB
CCC
DDDD
EEEEE
Trace
Worked Walkthrough — top = 'E'
Trace each row letter i and how many times the inner loop prints it.
i
Inner runs
Printed row
Count
A
1×
A
1
B
2×
BB
2
C
3×
CCC
3
D
4×
DDDD
4
E
5×
EEEEE
5
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.
Code
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;
}
Output
A
BB
CCC
DDDD
EEEEE
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;
}
Output (when user enters 4)
Enter the number of rows: 4
A
BB
CCC
DDDD
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;
}
Output
A
B B
C C C
D D D D
E E E E E
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.
Analysis
Time and Space Complexity
Program
Time
Extra space
Fixed / input / spaced forms
O(n²)
O(1)
Total letters printed = 1 + 2 + … + n = n(n+1)/2, which is quadratic in the number of rows.
Remember
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.
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.