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 (A, C, E, G, I). Compare program 13, where a running counter drives letters across rows.

⭐ Pattern Output

Five rows, no spaces between letters:

Output
A
ABC
ABCDE
ABCDEFG
ABCDEFGHI
1

Complete C# Program (Through 'I')

Outer loop steps by 2 from 'A' to 'I'. Inner loop prints 'A' through i each row.

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            for (char i = 'A'; i <= 'I'; i += (char)2)
            {
                for (char j = 'A'; j <= i; j++)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }
        }
    }
}

🧠 How It Works

1

Outer loop picks the ending letter

i takes A, C, E, G, I by using i += 2.

Odd steps
2

Inner loop prints A..i

j always starts at A and prints all letters up to the current i.

Prefix
3

Odd row lengths

If the ending letters are A, C, E, G, I then the counts are 1, 3, 5, 7, 9.

1..9 odd
=

Complexity

For r rows, total prints are \(1+3+\dots+(2r-1)=r^2\), so complexity is O(r²).

2

Variation — User Input Version

Read the ending letter for the last row (like I). Step by 2 from A to that letter.

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter the ending letter (odd step like I): ");
            char end = Convert.ToChar(Console.ReadLine());

            for (char i = 'A'; i <= end; i += (char)2)
            {
                for (char j = 'A'; j <= i; j++)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }
        }
    }
}

💡 Tips for Enhancement

Try These

  • Use lowercase by switching to 'a' and an odd ending letter
  • Try spaces between letters if you want a wider look
  • Compare with Program 1 (A, AB, ABC, ...)
  • Compare with Program 13 (continuous counter)

Avoid

  • Starting the inner loop at the ending letter (that would skip A and change the pattern)
  • Using an even ending letter if you expect exactly r rows of odd lengths
  • Letting the pattern run past 'Z' unintentionally

Key Takeaways

1

Outer loop steps by 2 to pick odd-ending letters (A, C, E...).

2

Inner loop prints the prefix A..end each row.

3

Row lengths are odd numbers: 1, 3, 5, ...

4

Total work for r rows is \(r^2\) prints.

❓ Frequently Asked Questions

It makes the ending letter jump by two (A, C, E, ...) so each row length increases by two characters.
\(1+3+\dots+(2r-1)=r^2\).
O(r²) for r rows.

Explore More C# Alphabet Patterns!

Changing the outer step from 1 to 2 is a simple way to create odd-width shapes.

All Alphabet Patterns →
Did you know?

Odd numbers add up to perfect squares: \(1+3+5+\dots+(2r-1)=r^2\). That’s why this pattern prints exactly \(r^2\) letters for r rows.

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