Right-Angled Triangle Alphabet Pattern in C#

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

What You’ll Learn

How to print an alphabet right-angled triangle in C#: each row starts at 'A' and extends one letter further than the previous row, using nested for loops and Console.Write.

With five rows, the output is A, AB, ABC, ABCD, and ABCDE—the same triangle shape as a star pattern, but with letters.

⭐ Pattern Output

For 5 rows, the pattern looks like this:

Output
A
AB
ABC
ABCD
ABCDE
1

Complete C# Program

Fixed five rows: outer loop picks the last letter on each row ('A' to 'E'); inner loop prints from 'A' through that letter.

C#
using System;

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

🧠 How It Works

1

Outer loop (rows)

The outer loop runs i from 'A' through 'E'. Each value represents the last letter to print on that row.

Row control
2

Inner loop (letters)

For each row, the inner loop starts from 'A' and prints up to i using Console.Write(j).

Print letters
3

New line

After printing one row, Console.WriteLine() moves output to the next line so the next row starts cleanly.

Next row
=

Right-angled letter triangle

You print 1+2+…+n letters in total, so time complexity is O(n²) for n rows.

2

Variation — User Input Version

Read the number of rows and print up to the corresponding last letter:

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter the number of rows: ");
            int rows = Convert.ToInt32(Console.ReadLine());

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

💡 Tips for Enhancement

Try These

  • Validate input with int.TryParse before using rows
  • Print lowercase by starting from 'a' instead of 'A'
  • Add spaces between letters for readability
  • Try reverse order patterns next (e.g., CBA, DCBA)

Avoid

  • Using a negative row count (guard against invalid input)
  • Forgetting Console.WriteLine() after each row
  • Letting 'A' + rows go past 'Z' without handling wrapping

Key Takeaways

1

Each row starts at 'A' and grows by one letter.

2

Nested loops map naturally to row/column pattern output.

3

Complexity is O(n²) for n rows.

4

You can generalize the last letter with 'A' + rows - 1.

❓ Frequently Asked Questions

Because the inner loop always starts from 'A' and only the upper bound changes with the outer-loop letter.
Use a separate char ch that you increment across prints and don’t reset it after each row.
O(n²) for n rows because you print 1+2+…+n characters.

Explore More C# Alphabet Patterns!

Letter triangles and pyramids build on the same nested-loop idea you used here.

All Alphabet Patterns →
Did you know?

In C#, char values can be incremented: 'A' + 1 becomes 'B'. That’s why looping from 'A' to 'A' + rows - 1 works naturally for this pattern.

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