Odd-Length Alphabet Triangle in C

What You’ll Learn
Each row is a block of letters from A through the next “odd step” in the alphabet: A, ABC, ABCDE, ABCDEFG, ABCDEFGHI.
The outer loop uses i += 2 (values A, C, E, G, I); compare program 13, where width grows by one each row and a separate counter drives the letters.
⭐ Pattern Output
Five rows, no spaces between letters:
A
ABC
ABCDE
ABCDEFG
ABCDEFGHIComplete C Program (Through 'I')
Outer i steps by 2 from 'A' to 'I'. Inner j prints every code from 'A' through i. (Equivalent ASCII form: for (i = 65; i <= 73; i += 2).)
#include <stdio.h>
int main() {
int i, j;
for (i = 'A'; i <= 'I'; i += 2) {
for (j = 'A'; j <= i; ++j) {
printf("%c", j);
}
printf("\n");
}
return 0;
}🧠 How It Works
i += 2 on the outer loop
The peak letter for each row jumps by two in ASCII: A, C, E, G, I. That makes every row an odd-length prefix of the alphabet instead of the usual consecutive growth.
Inner j from 'A' to i
Each row reprints from the beginning of the alphabet up to the current i. So when i == 'C' you emit ABC; when i == 'E' you emit ABCDE.
printf("%c", j)
The loop variable j is already a character code. Printing it directly avoids a separate k counter while still walking contiguous letters.
New line per outer step
After the inner loop drains 'A'…i, printf("\n") starts the next row with the next odd peak letter.
Odd-width prefixes
Row lengths are 1, 3, 5, 7, 9 because i steps by two; total prints 1+3+5+7+9 = 25 = 5². For r such rows you print r² letters and spend O(r²) time in the nested loops.
Variation — Ending Letter from Input
User supplies the last outer value (should be an odd-position letter from A: A, C, E, …). scanf(" %c", ...) skips spaces/newlines before the letter.
#include <stdio.h>
int main() {
int i, j;
char endChar;
printf("Enter the ending letter (e.g. E for A,C,E rows): ");
scanf(" %c", &endChar);
for (i = 'A'; i <= endChar; i += 2) {
for (j = 'A'; j <= i; ++j) {
printf("%c", j);
}
printf("\n");
}
return 0;
}💡 Tips for Enhancement
Try These
- ASCII twin:
for (i = 65; i <= 73; i += 2)andjfrom65toi - Even-end variant: start at
'B'and step by 2 for B, D, F, … - Validate
endCharis uppercase and on an odd index from A if you need a predictable shape
Avoid
- Using
%cwithout a leading space inscanfafter other reads (newline gets consumed as the letter) - Mixing up “odd length” with “odd ASCII code” — here it is odd count per row (1,3,5,…)
Key Takeaways
i += 2 picks every other letter for the row end marker.
Inner loop always runs 'A'..i, so widths grow by 2 each row.
Total prints for r such rows: r² (here 5² = 25).
Prefer i <= 'I' over a magic upper bound like 74 for the five-row sample.
❓ Frequently Asked Questions
i <= 73 for this step, but 73 or 'I' matches the last row you want and is easier to reason about.i = 'A' (since the next value 'C' would exceed B). For the full ladder through B, you would change the loop design (e.g. step by 1 or different condition).Explore More C Alphabet Patterns!
Changing the outer step size is an easy way to reshape how fast each row grows.
Some older samples use for (i = 65; i <= 74; i += 2); the last iteration is still i = 73 ('I'). Writing i <= 73 or i <= 'I' states the intent clearly.
12 people found this page helpful
