Odd-Length Alphabet Triangle in C

Beginner
⏱️ 8 min read
📚 Updated: Aug 2026
🎯 3 Code Examples
🚀 Live Preview
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 (A, C, E, G, I). Compare Program 1 (step 1) and Program 13 (running counter). Includes a live preview, worked C examples, edge cases, and complexity.

Shape Rule

Odd widths 1, 3, 5…

Each row prints the prefix A..end where end is A, C, E, G, I.

Outer Loop

Step by 2

for (i = 'A'; i <= 'I'; i += 2) picks the end letter.

Inner Loop

Print A..i

for (j = 'A'; j <= i; ++j) restarts at A every row.

printf vs putchar

Same line / next line

Letters use printf("%c", j); end each row with printf("\n").

Live Preview

1–13 rows

Pick a row count and draw the odd-length triangle in the browser.

O(r²)

Complexity

Total letters = ; extra memory stays O(1).

Introduction

An odd-length alphabet triangle grows by two letters on each new line. Every row still starts at A, but the ending letter jumps A → C → E → G → I, so widths are 1, 3, 5, 7, 9.

In C you usually solve it with two nested for loops: the outer loop steps the end letter by 2, the inner loop prints A through that end letter, then printf("\n") moves to the next line.

Why it matters?

It shows that changing only the outer step (1 vs 2) transforms Program 1 into an odd-width triangle — and that odd-number sums equal perfect squares, which makes complexity analysis concrete.

Key Highlights

Odd Widths

Row lengths are 1, 3, 5, 7, 9, …

Step by Two

Outer end letter jumps with i += 2.

Fresh Prefix

Inner loop always restarts at A.

r² Letters

Odd sum identity: total prints equal .

In short: outer loop ends at A, C, E, … with i += 2; each row prints A..i with printf("%c", j), then printf("\n").

📝 Problem & Approach

Given a row count r (or a fixed odd-step ending letter like 'I'), print a left-aligned triangle of alphabet prefixes with odd lengths.

c
// First 5 rows (conceptual shape)
// A
// ABC
// ABCDE
// ABCDEFG
// ABCDEFGHI

Inputs & Outputs

ItemTypeDescription
rows / end letterint / charNumber of odd-length lines (1–13 for A–Y), or last end letter such as 'I'.
Printed outputtextLeft-aligned rows; row k prints letters from A through 'A' + 2*(k-1).

Minimal workflow

Pseudocode
for end in A, C, E, ... up to last:
    for ch from A to end:
        print ch (no newline)
    print newline

Approach comparison

ApproachIdeaBest for
Char i += 2Outer end letter steps by twoLearning and interviews
Row index formulaend = 'A' + 2*(row-1)Clearer when input is a row count

⚡ Quick Reference

GoalPattern
Step end lettersfor (i = 'A'; i <= 'I'; i += 2)
Print prefix A..ifor (j = 'A'; j <= i; ++j) printf("%c", j);
End the rowprintf("\n");
End from row indexend = 'A' + 2 * (row - 1);
Step-1 triangleSee Program 1 (A, AB, ABC, …)

📋 printf vs putchar vs i += 2

Same triangle — different roles for each tool.

printf("%c", j)
same line

Prints a letter without moving to the next line

printf("\n")
new line

Ends the current row after the prefix is printed

i += 2
odd ends

Jumps the ending letter A → C → E …

Learning tip
int step

In C, i += 2 works with int i — no cast needed

Context

When This Pattern Shows Up

Reach for this triangle when practicing loop steps and odd-width prefixes.

  1. After Program 1

    Change only the outer step from 1 to 2 for odd widths.

  2. Step-size drills

    Practice += 2 on chars and int row formulas.

  3. Math intuition labs

    Odd sums equal squares — count printed letters for small r.

  4. Gateway to Program 15

    Next: symmetric alphabet rows with a star center.

  5. Not a UI layout tool

    This is a console teaching pattern — not how you build modern app screens.

Key benefit: one small program that links loop step size, odd widths, and the classic odd-sum = square identity.

🔮 Live Preview

Choose a row count between 1 and 13 and draw the odd-length alphabet triangle in the browser.

Try 5 (through I) or 3 (through E). Max 13 keeps the last end letter at Y.

Live result
Press "Draw pattern".

Examples Gallery

Three complete C programs — fixed through I, ending-letter input, and a row-count formula. Click View Output to reveal sample console results.

📚 Getting Started

Print five odd-length rows with i += 2.

Example 1 — Fixed through 'I'

Hard-coded ending letter — ideal for first demos and screenshots.

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

When i = 'A', the inner loop prints A. When i = 'C', it prints ABC, and so on through ABCDEFGHI. With int i, i += 2 needs no cast (unlike C#’s (char)2).

📈 Practical Variant

Let the user choose the last ending letter.

Example 2 — Ending Letter Input

Read an odd-step ending letter (A, C, E, …). Prefer validating a single A–Z character in real apps.

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;
}

How It Works

Same nested-loop core as Example 1; only the outer upper bound changes. Prefer odd-step endings (A, C, E, …). The leading space in scanf(" %c", ...) skips leftover newlines.

⚡ Row-Count Style

Drive the pattern from a row count instead of an ending letter.

Example 3 — end = 'A' + 2*(row-1)

Clear when the user enters how many rows to print.

c
#include <stdio.h>

int main() {
    int rows = 5;
    int row, j;
    char end;

    for (row = 1; row <= rows; ++row) {
        end = 'A' + 2 * (row - 1);
        for (j = 'A'; j <= end; ++j) {
            printf("%c", j);
        }
        printf("\n");
    }

    return 0;
}

How It Works

Row 1 ends at A + 0, row 2 at A + 2, row 3 at A + 4, and so on. Clamp rows to 1–13 so end stays within A–Y.

🧠 How the Algorithm Prints Rows

1

Set up

#include <stdio.h> brings in printf / scanf. Choose a last end letter or a row count.

Setup
2

Outer loop (end letter)

i takes A, C, E, G, I by using i += 2 (with int i).

Odd steps
3

Inner loop (prefix)

j always starts at A and prints every letter up to the current i.

A..i
4

New line

printf("\n") ends the row so the next outer iteration starts fresh.

Break
=

Triangle complete

Total letters: 1+3+…+(2r-1) = O(r²) time, O(1) extra memory.

🔎 Worked Walkthrough — through 'I'

Trace each outer-loop value of i and count how many letters the inner loop prints.

iInner j rangePrinted rowLength
'A''A'..'A'A1
'C''A'..'C'ABC3
'E''A'..'E'ABCDE5
'G''A'..'G'ABCDEFG7
'I''A'..'I'ABCDEFGHI9

Total letter prints: 1 + 3 + 5 + 7 + 9 = 25 = .

Use Cases

Where this tiny pattern (and its step-by-2 idea) shows up beyond the homework prompt.

1. Loop Step Practice

Clearest demo that the outer increment controls width growth.

Example: change += 2 to += 1 and watch Program 1 appear.

2. Contrast with Program 1

Teach step size as a one-line difference between patterns.

Example: side-by-side A/AB/ABC vs A/ABC/ABCDE.

3. Odd-Sum Identity

Count letters to see that odd totals equal squares.

Example: 5 rows → 25 = 5² prints.

4. Case & Spacing Variants

Lowercase or spaced letters once the loops work.

Example: start from 'a' with the same += 2.

5. Complexity Intuition

Square totals make O(r²) concrete without triangular formulas.

Example: r = 10 → 100 letter prints.

6. Input Style Labs

Practice both ending-letter and row-count APIs for the same shape.

Example: map rows=3 ↔ end='E'.

Pro Tip: say “outer picks the odd end letter, inner prints A through that end” before coding — that story prevents forgetting to restart at A.

Advantages

Why this pattern earns a spot right after the classic A/AB/ABC triangle.

  1. 1. Instant Visual Feedback

    Wrong step size shows up immediately as consecutive widths instead of odd ones.

  2. 2. Minimal Concepts

    Only nested loops and a step of 2 — no arrays required.

  3. 3. Easy to Mirror

    Flip back to Program 1 by changing the outer step to 1.

  4. 4. Clean Complexity Story

    Total work is exactly — memorable for interviews.

Pro Tip: learn the i += 2 version first; treat the row-index formula as an equivalent rewrite afterward.

Usage Tips

Small habits that keep odd-length alphabet code clean.

  1. 1. Use int for the Outer Index

    With int i, write i += 2 — no cast needed (unlike C# char arithmetic).

  2. 2. Prefer Odd Endings

    Use A, C, E, …, Y when you want clean odd lengths from row 1.

  3. 3. Always Restart at A

    Inner loop must begin at 'A' every row for this prefix shape.

  4. 4. Clamp to 13 Rows

    Row 13 ends at Y; row 14 would leave A–Z.

  5. 5. Dry-Run One Small r

    Trace 3 rows (A / ABC / ABCDE) on paper before coding larger demos.

Pro Tip: if you get A, AB, ABC instead of A, ABC, ABCDE, you used step 1 instead of step 2.

Common Pitfalls

Mistakes that commonly break odd-length alphabet patterns.

  1. 1. Using Step 1 Instead of Step 2

    You get Program 1’s consecutive widths (A, AB, ABC, …).

    → Keep i += 2 (or 2*(row-1) for the end letter).

  2. 2. Starting the Inner Loop at i

    Skipping A produces single letters or wrong prefixes.

    → Always for (j = 'A'; j <= i; ++j).

  3. 3. Missing Space in scanf(" %c")

    Without the leading space, a leftover newline can be read as the “letter.”

    → Prefer scanf(" %c", &endChar) after prompts, or drive the pattern from a row count.

  4. 4. Unchecked scanf

    Empty or multi-character input leaves endChar / rows uninitialized or wrong.

    → Check scanf’s return value; validate a single A–Z letter or a positive row count.

  5. 5. Too Many Rows

    Beyond 13 rows the end letter leaves A–Z.

    → Clamp to 1–13 or stop when end > 'Z'.

Edge Cases

Check these inputs before calling the solution done.

rows = 1

Single letter

Output is just A on one line.

end = E

Three rows

Prints A / ABC / ABCDE.

Even end

Like B or D

Still runs, but odd-length alignment from A is messier — prefer odd-step ends.

rows = 13

Last A–Z fit

End letter Y; 13² = 169 prints.

Bad input

Empty / multi-char

Unchecked scanf fails silently — check the return value.

Case

Lowercase variant

Same loops work with 'a' and += 2.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Flip to Program 1

2. Even-length cousin

  • Start at B and step by 2
  • Widths 2, 4, 6, …

3. Count the letters

  • Verify total prints equal
  • Great interview talking point

4. Continue to Program 15

Notes

  • Square count. Total letters for r rows is — hence O(r²) time.
  • Outer step picks the end letter; inner loop always restarts at A.
  • In C, use int i and i += 2 — no cast needed.
  • Clamp to 13 rows (end = Y) for A–Z-only demos.

Quick Takeaway: outer loop steps the end letter by 2, inner loop prints A through that end, then break the line — that is the whole pattern.

⏱️ Time and Space Complexity

ProgramTimeExtra space
Nested loops (Examples 1–3)O(r²)O(1)

Because 1+3+…+(2r-1)=r², the letter count is exactly a perfect square.

Wrap Up

🎉 Conclusion

The odd-length alphabet triangle is a small nested-loop exercise with lasting payoff: outer step size, prefix printing, and the odd-sum = square identity. Master the i += 2 version, then optionally drive it from a row count with 'A' + 2*(row-1).

Practice the three examples above, then continue to Program 15’s symmetric alphabet-with-stars pattern.

Step the end letter by 2, always restart the inner loop at A, and remember total prints equal .

💡 Best Practices

✅ Do

  • Use i += 2 (or the row-index end formula)
  • Restart the inner loop at 'A' every row
  • Prefer odd-step ending letters for clean odd widths
  • Clamp to 1–13 rows for A–Z demos
  • State that total prints equal when asked about complexity

❌ Don’t

  • Use step 1 when you meant odd widths
  • Start the inner loop at the end letter
  • Skip the leading space in scanf(" %c", ...)
  • Ignore validation on ending-letter input
  • Allow more than 13 rows without a past-Z policy

Key Takeaways

Knowledge Unlocked

Five things to remember about this alphabet pattern

Print the odd-length triangle the beginner-friendly way.

5
Core concepts
+2 02

Outer loop

End letters A, C, E…

Code
A 03

Inner loop

Prints A..end each row

Code
04

New line

Ends each row

I/O
05

Complexity

O(r²) time

Analysis

❓ Frequently Asked Questions

It makes the ending letter jump by two (A, C, E, ...) so each row length increases by two characters and stays odd.
The outer loop advances the ending letter by 2 (A, C, E, G, I). The inner loop prints every letter from A through that ending letter, so the count is always odd.
Because each row is a fresh prefix A..end. Starting at the end letter would skip earlier letters and change the pattern.
printf("%c", j) prints a letter and stays on the same line. printf("\n") ends the current line after the inner loop.
1+3+…+(2r-1)=r². For 5 rows that is 25 letters.
O(r²) for r rows, because total letter prints equal r².
The loop still runs, but you no longer get a clean set of odd-length rows aligned to A, C, E, …. Prefer an odd-step ending letter (A, C, E, …, Y) for this pattern.
For a row count, check scanf("%d", &rows) == 1. For an ending letter, use scanf(" %c", &endChar) (leading space skips whitespace) and keep the letter within A–Z.

Did you Know? 🔊

Odd numbers add up to perfect squares: 1+3+5+…+(2r-1)=r². That is why this pattern prints exactly letters for r rows — the same count that makes the complexity O(r²).

Continue to Alphabet Pattern 15

Next up: symmetric alphabet rows with stars filling the center.

Program 15 tutorial →

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