Odd-Length Alphabet Triangle in C

Beginner
⏱️ 6 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Nested Loops

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:

Output
A
ABC
ABCDE
ABCDEFG
ABCDEFGHI
1

Complete 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).)

c
#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

1

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.

Step
2

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.

Prefix
3

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.

Print
4

New line per outer step

After the inner loop drains 'A'i, printf("\n") starts the next row with the next odd peak letter.

Row
=

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.

2

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.

c
#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) and j from 65 to i
  • Even-end variant: start at 'B' and step by 2 for B, D, F, …
  • Validate endChar is uppercase and on an odd index from A if you need a predictable shape

Avoid

  • Using %c without a leading space in scanf after 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

1

i += 2 picks every other letter for the row end marker.

2

Inner loop always runs 'A'..i, so widths grow by 2 each row.

3

Total prints for r such rows: r² (here 5² = 25).

4

Prefer i <= 'I' over a magic upper bound like 74 for the five-row sample.

❓ Frequently Asked Questions

So the end letter of each row skips every second character (A, C, E, …). That makes each new row exactly two letters longer than the previous.
It works the same as i <= 73 for this step, but 73 or 'I' matches the last row you want and is easier to reason about.
You get only 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).
O(r²) prints for r rows in this family.

Explore More C Alphabet Patterns!

Changing the outer step size is an easy way to reshape how fast each row grows.

All Alphabet Patterns →
Did you know?

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.

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