Repeating-Letter Alphabet Triangle in C#

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

What You’ll Learn

Row 1 is one A, row 2 is two Bs, row 3 three Cs, and so on: A, BB, CCC, DDDD, EEEEE.

This is a great contrast to program 1, where letters change inside each row (A, AB, ABC...). Here, the row letter stays the same and only the count grows.

⭐ Pattern Output

For 5 rows:

Output
A
BB
CCC
DDDD
EEEEE
1

Complete C# Program

The inner loop runs the correct number of times, but always prints i (the row 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(i);
                }
                Console.WriteLine();
            }
        }
    }
}

🧠 How It Works

1

Outer loop selects the row letter

i runs from 'A' to 'E'. That’s the character printed on the row.

Row character
2

Inner loop controls the repeat count

j runs from 'A' to i, so it executes 1, 2, 3, 4, then 5 times.

1..5 repeats
3

Print i, not j

Printing i keeps the whole row the same letter. Printing j would change letters across the row (a different pattern).

Key idea
=

Same triangle shape

Total prints are 1+2+…+n for n rows, so time complexity is O(n²).

2

Variation — User Input Version

For a dynamic row count, compute the row letter from the row number. Keep rows within 26 if you want only A–Z.

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 (int row = 1; row <= rows; row++)
            {
                char ch = (char)('A' + row - 1);
                for (int col = 1; col <= row; col++)
                {
                    Console.Write(ch);
                }
                Console.WriteLine();
            }
        }
    }
}

💡 Tips for Enhancement

Try These

  • Use lowercase by replacing 'A' with 'a'
  • Add a space after each letter to make the triangle wider and easier to read
  • Compare with Program 1 (letters change across the row)
  • Cap rows at 26 if you want to stay in A–Z

Avoid

  • Printing j instead of the row letter if you want repeats
  • Incrementing the character inside the inner loop (that changes the pattern)
  • Allowing very large rows without deciding what to do after 'Z'

Key Takeaways

1

The row letter is chosen by the outer loop.

2

The inner loop only controls the number of repeats.

3

Printing i (not j) is what makes the row uniform.

4

Time complexity is O(n²) for n rows.

❓ Frequently Asked Questions

On the third row, the row letter is C, and the inner loop runs three times, printing C each time.
Yes. You can compute it from the row index: ch = (char)('A' + row - 1).
O(n²) for n rows.

Explore More C# Alphabet Patterns!

A one-line change inside the inner loop can switch between “repeating letters” and “stepping letters” patterns.

All Alphabet Patterns →
Did you know?

Instead of carrying a variable like ch++ across rows, you can compute the row character directly from the row number using (char)('A' + row - 1).

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