Symmetric Alphabet, Star Center in C#

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

What You’ll Learn

Build rows that read the same on letters from both ends, while * fills the center gap as the row shortens.

For top = 'E', the output begins with ABCDEEDCBA and ends with A********A.

⭐ Pattern Output

For 5 rows:

Output
ABCDEEDCBA
ABCD**DCBA
ABC****CBA
AB******BA
A********A
1

Complete C# Program (Five Rows)

Three parts per row: left letters (A..i), stars (2*(top-i)), then right letters (i..A).

C#
using System;

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

            for (char i = top; i >= 'A'; i--)
            {
                for (char j = 'A'; j <= i; j++)
                {
                    Console.Write(j);
                }

                int stars = 2 * (top - i);
                for (int s = 1; s <= stars; s++)
                {
                    Console.Write("*");
                }

                for (char m = i; m >= 'A'; m--)
                {
                    Console.Write(m);
                }

                Console.WriteLine();
            }
        }
    }
}

🧠 How It Works

1

Outer loop picks row end

The row end letter i goes from E down to A.

E → A
2

Left half prints A..i

That gives ABCDE, then ABCD, then ABC, etc.

Prefix
3

Stars fill the center gap

Star count is 2 * (top - i): 0, 2, 4, 6, 8.

Gap
=

Mirrored right half

Finally, print i..A to mirror the left side.

2

Variation — User Input Version

Read rows, compute top, then reuse the same idea. (If rows > 26, you will go beyond 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 top = (char)('A' + rows - 1);

            for (char i = top; i >= 'A'; i--)
            {
                for (char j = 'A'; j <= i; j++)
                {
                    Console.Write(j);
                }

                int stars = 2 * (top - i);
                for (int s = 1; s <= stars; s++)
                {
                    Console.Write("*");
                }

                for (char m = i; m >= 'A'; m--)
                {
                    Console.Write(m);
                }

                Console.WriteLine();
            }
        }
    }
}

💡 Tips for Enhancement

Try These

  • Replace * with another symbol (like #)
  • Add a space between characters if you want a wider output
  • Compare with star patterns (same center-gap idea)
  • Cap rows at 26 to stay inside A–Z

Avoid

  • Forgetting the mirror half (you’ll lose symmetry)
  • Using an incorrect star count (it must be even for this output)
  • Printing the left half in reverse (that changes the pattern)

Key Takeaways

1

Row end letter moves from top down to A.

2

Left prints A..end; right prints end..A.

3

Stars fill the middle as 2*(top-end).

4

Time complexity is O(n²).

❓ Frequently Asked Questions

Because it is computed as 2*(top - i), which is always a multiple of 2.
Yes. You can start the right half from (char)(i - 1) instead of i when there are zero stars.
O(n²) for n rows.

Explore More C# Alphabet Patterns!

Center gaps (stars/spaces) are a classic trick for symmetric patterns.

All Alphabet Patterns →
Did you know?

On each row, the total output width stays constant: left letters \(+\) stars \(+\) right letters \(=\) \(2n\) characters for \(n\) rows (here \(2 \times 5 = 10\)).

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