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 (Classic Codetofun Form)

Outer i steps by 2 from 65 while i <= 74 (same effect as i <= 73 or i <= 'I'). Inner j prints every code from 65 through i.

C++
#include <iostream>
using namespace std;

int main() {
    int i, j;
    for (i = 65; i <= 74; i += 2) {
        for (j = 65; j <= i; j++)
            cout << (char) j;
        cout << "\n";
    }
    return 0;
}

🧠 How It Works

1

i += 2

Outer loop visits A, C, E, G, I — every other capital letter.

Step
2

Inner j from 65 to i

Always rebuilds the prefix from the start of the alphabet up to the current end letter.

Prefix
3

cout << (char) j

Emits each letter in that range; no separate running counter is needed.

Print
4

New line per outer step

After finishing one prefix, move to the next wider odd-length row.

Row
=

25 characters total

1+3+5+7+9 = 25; for r rows this is r² prints.

2

Variation — Ending Letter from Input

User supplies the last outer value (odd-position letter from A: A, C, E, …). Use cin >> ws before cin >> endChar if prior reads might leave whitespace.

C++
#include <iostream>
using namespace std;

int main() {
    int i, j;
    char endChar;

    cout << "Enter the ending letter (e.g. E for A,C,E rows): ";
    cin >> ws >> endChar;

    for (i = 'A'; i <= endChar; i += 2) {
        for (j = 'A'; j <= i; j++)
            cout << (char) j;
        cout << "\n";
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Clearer bound: for (i = 'A'; i <= 'I'; i += 2) with inner j from 'A' to i
  • Even-end variant: start at 'B' and step by 2 for B, D, F, …
  • Validate endChar if you need a predictable ladder shape

Avoid

  • Mixing up “odd length” with “odd ASCII code” — here it is odd count per row (1, 3, 5, …)
  • Reading endChar without skipping whitespace when the buffer still has a newline

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 loose numeric bound when you want five rows through I.

❓ Frequently Asked Questions

So the end letter of each row skips every second character (A, C, E, …). Each new row is exactly two letters longer than the previous.
It matches the classic codetofun sample and stops after i = 73 ('I'). Using i <= 73 or i <= 'I' states the intent more clearly.
You get only i = 'A' (since 'C' would exceed B). For a full ladder through B, you would change the loop design.
O(r²) prints for r rows in this family.

Explore More C++ Alphabet Patterns!

Changing the outer step size reshapes how fast each row grows—compare program 1’s step-by-one width with this odd-width ladder.

All Alphabet Patterns →
Did you know?

Row lengths 1, 3, 5, …, (2r−1) sum to r². So five rows always print exactly 25 characters, same as a 5×5 block of letters would if you filled it cleverly.

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