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 (A, C, E, G, I). Compare program 13, where a running counter drives letters across rows.
⭐ Pattern Output
Five rows, no spaces between letters:
A
ABC
ABCDE
ABCDEFG
ABCDEFGHIComplete C# Program (Through 'I')
Outer loop steps by 2 from 'A' to 'I'. Inner loop prints 'A' through i each row.
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
Outer loop picks the ending letter
i takes A, C, E, G, I by using i += 2.
Inner loop prints A..i
j always starts at A and prints all letters up to the current i.
Odd row lengths
If the ending letters are A, C, E, G, I then the counts are 1, 3, 5, 7, 9.
Complexity
For r rows, total prints are \(1+3+\dots+(2r-1)=r^2\), so complexity is O(r²).
Variation — User Input Version
Read the ending letter for the last row (like I). Step by 2 from A to that letter.
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
Outer loop steps by 2 to pick odd-ending letters (A, C, E...).
Inner loop prints the prefix A..end each row.
Row lengths are odd numbers: 1, 3, 5, ...
Total work for r rows is \(r^2\) prints.
❓ Frequently Asked Questions
Explore More C# Alphabet Patterns!
Changing the outer step from 1 to 2 is a simple way to create odd-width shapes.
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.
12 people found this page helpful
