Symmetric Decreasing Alphabet Square in C#

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

What You’ll Learn

This pattern stays symmetric by printing a left half (E down to A) and then a mirrored right half (B up to E).

Each printed cell follows the same rule: if j > i print the column letter; otherwise print the current row floor i.

⭐ Pattern Output

Output for 5 rows (a space after each letter):

Output
E E E E E E E E E
E D D D D D D D E
E D C C C C C D E
E D C B B B C D E
E D C B A B C D E
1

Complete C# Program (A–E)

Two symmetric scans per row with the same j > i check, matching the reference logic.

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = 4; // index for 'E'
            char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();

            for (int i = k; i >= 0; i--)
            {
                for (int j = k; j >= 0; j--)
                {
                    Console.Write(j > i ? $"{alpha[j]} " : $"{alpha[i]} ");
                }

                for (int j = 1; j <= k; j++)
                {
                    Console.Write(j > i ? $"{alpha[j]} " : $"{alpha[i]} ");
                }

                Console.WriteLine();
            }
        }
    }
}

🧠 How It Works

1

Map letters to numeric indices

We store letters in alpha. For A–E, we set k = 4 (index of E).

Every printed cell is one of alpha[0..k].

Setup
2

Outer loop drops the “floor” each row

Row index i runs from k down to 0 (E to A). Smaller i means a deeper inner layer.

Think of alpha[i] as the minimum letter allowed in that row.

Rows
3

Left half: E down to A (k..0)

For columns j = k..0, we choose what to print with the same rule:

j > i ? alpha[j] : alpha[i]

So the border stays high (E, D, C, …), but the interior drops to the row floor letter.

Left
4

Right half: B up to E (1..k)

To mirror the left side, we scan j = 1..k. Starting at 1 (B) avoids printing the center A twice.

Total columns per row: \((k+1) + k = 2k + 1\). For A–E (\(k=4\)), width is 9 letters.

Right
=

Symmetry + layers

Each row is a symmetric “layer” around the center. As i decreases, the minimum letter moves inward (E → D → C → B → A).

2

Variation — User Input Top Letter

Let the user pick the top letter (like E). This version works for A..top and prints the same symmetric square.

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter top letter (like E): ");
            char top = Convert.ToChar(Console.ReadLine());

            int k = top - 'A';
            char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();

            for (int i = k; i >= 0; i--)
            {
                for (int j = k; j >= 0; j--)
                    Console.Write(j > i ? $"{alpha[j]} " : $"{alpha[i]} ");

                for (int j = 1; j <= k; j++)
                    Console.Write(j > i ? $"{alpha[j]} " : $"{alpha[i]} ");

                Console.WriteLine();
            }
        }
    }
}

💡 Tips for Enhancement

Try These

  • Change the separator (space) to two spaces for wider output
  • Print without trailing spaces by building a string per row
  • Try the same rule with numbers (5..1) instead of letters
  • Compare with Program 21 for symmetry + shape ideas

Avoid

  • Starting the second half at 0 (it would duplicate A in the middle)
  • Letting input exceed Z without handling it
  • Mixing different alphabets/arrays without adjusting k

Key Takeaways

1

Two halves create symmetry (E..A then B..E).

2

Condition j > i chooses border vs interior.

3

Center drops to A on the last row.

4

Total work is O(n²).

❓ Frequently Asked Questions

The first loop prints the left half (E down to A). The second prints the mirrored right half (B up to E) so A appears once in the middle.
Pick a larger top letter (like H), set k = top - 'A', and keep the same loop structure.
O(n²) for n letters, because there are n rows and each row prints O(n) cells.

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