Sequential Alphabet Triangle in C

What You’ll Learn
Each row is wider than the last, but letters stay in order across the whole shape: A, then B C, then D E F, up to K L M N O for five rows (with spaces between letters on each row).
This differs from program 1 style triangles where the inner loop uses 'A' + j per column; here one counter k walks the alphabet continuously.
⭐ Pattern Output
For 5 rows (space after each letter):
A
B C
D E F
G H I J
K L M N OComplete C Program (Five Rows, ASCII Loops)
Loop variables i and j use ASCII codes 65–69 ('A'–'E') to control row width. The actual letters come from k, incremented in printf.
#include <stdio.h>
int main() {
int i, j;
int k = 65;
for (i = 65; i <= 69; ++i) {
for (j = 65; j <= i; ++j) {
printf("%c ", k++);
}
printf("\n");
}
return 0;
}🧠 How It Works
k = 65 ('A')
This is the running letter stream. It keeps increasing across the whole program, so the second row continues from where the first row left off instead of restarting at A.
Outer i as ASCII bound
i walks 65–69 (A–E). The inner loop j from 65 to i only decides how many cells belong to this row; the actual symbols always come from k.
printf("%c ", k++)
Each cell prints the current k as a character, prints a space, then post-increments k. That stitches one continuous sequence A, B, C, … across the triangle.
printf("\n") between rows
When the inner loop finishes, you have printed exactly i - 64 letters on that row (for this i range). The newline moves to the next row while k stays ready for the next value.
Continuous flood-fill
Fifteen letters for five rows is still n(n+1)/2. Nested loops over row length give O(n²) character output for n rows (plus spaces).
Variation — User Input + Character Literals
Same idea with readable 'A' bounds; last row ends at 'A' + rows - 1.
#include <stdio.h>
int main() {
int rows;
int i, j;
char k = 'A';
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 'A'; i <= 'A' + rows - 1; ++i) {
for (j = 'A'; j <= i; ++j) {
printf("%c ", k++);
}
printf("\n");
}
return 0;
}💡 Tips for Enhancement
Try These
- Fixed five rows with
char kandfor (i = 'A'; i <= 'E'; i++)— same output, clearer than65 - Use
printf("%c", k++)to drop spaces between letters - Cap
rowssokdoes not pass'Z'
Avoid
- Resetting
kto'A'at every row (you would repeatA,BB, … instead of a run-through) - Incrementing
konly once per row (not enough letters on wider rows)
Key Takeaways
Inner loop count matches row width; k carries the alphabet forward.
k++ (or k++ in printf) runs once per printed character.
O(n²) output size for n rows.
ASCII and character-literal loops are interchangeable here.
❓ Frequently Asked Questions
k.printf uses the value of k first, then k advances for the next character.i <= 'A' + rows - 1 (with i as char or int), inner j from 'A' to i, same k++ body.Explore More C Alphabet Patterns!
One running counter is a simple way to stream letters through any row layout.
You can write the fixed five-row version with char k = 'A' and for (i = 'A'; i <= 'E'; ++i) — identical behavior to the 65–69 version.
12 people found this page helpful
