Sequential Alphabet Triangle in C#

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

What You’ll Learn

Each row is wider than the last, but letters stay in order across the whole shape: A, then B C, then D E F, up to K L M N O for five rows (with spaces between letters).

This differs from program 1 style triangles where letters reset per row; here one counter walks the alphabet continuously.

⭐ Pattern Output

For 5 rows (space between letters):

Output
A
B C
D E F
G H I J
K L M N O
1

Complete C# Program

Use a single running character k starting at 'A'. Increment it after every print so letters stay consecutive across the whole triangle.

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            char k = 'A';

            for (int i = 1; i <= 5; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    Console.Write(k);
                    if (j < i) Console.Write(" ");
                    k++;
                }
                Console.WriteLine();
            }
        }
    }
}

🧠 How It Works

1

One running character

k starts at 'A' and never resets between rows.

Continuous
2

Outer loop sets row width

Row i prints i characters: 1, 2, 3, 4, 5.

1..5
3

Increment per character

The statement k++ runs inside the inner loop, so each printed cell advances to the next letter.

k++
=

Total letters printed

For 5 rows, you print 1+2+3+4+5 = 15 letters. In general it is \(n(n+1)/2\), so complexity is O(n²).

2

Variation — User Input Version

Read rows and keep printing until you finish. If you want to stay in A–Z only, cap rows (or stop when k passes '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());

            char k = 'A';
            for (int i = 1; i <= rows; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    Console.Write(k);
                    if (j < i) Console.Write(" ");
                    k++;
                }
                Console.WriteLine();
            }
        }
    }
}

💡 Tips for Enhancement

Try These

  • Remove spaces if you prefer a compact look
  • Use lowercase by starting k = 'a'
  • Compare with Program 1 (letters reset each row)
  • Stop when k reaches 'Z' if you want only A–Z

Avoid

  • Incrementing k only once per row (that would repeat the same letter on the row)
  • Assuming the alphabet wraps automatically after 'Z' (it doesn’t)
  • Printing i instead of k if you want sequential letters

Key Takeaways

1

Use one running character that never resets.

2

Increment inside the inner loop to advance per cell.

3

Row width is controlled by the outer loop (1..n).

4

Complexity is O(n²) for n rows.

❓ Frequently Asked Questions

Because k is updated after every printed character and is not reset inside the outer loop.
\(1+2+\dots+n = n(n+1)/2\).
O(n²) for n rows.

Explore More C# Alphabet Patterns!

Continuous counters like k are useful anytime you want values to flow across rows.

All Alphabet Patterns →
Did you know?

If you remove the spaces, the triangle becomes more compact, but the same k++ logic still produces consecutive letters.

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