Diamond-Shaped Alphabet Pattern in C#

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

What You’ll Learn

This pattern is a full diamond made by stacking the inverted V from program 33 and then mirroring it back upward.

The only extra trick: start the bottom half from D so the widest row (E) is printed only once.

⭐ Pattern Output

Output for AE (width \(2n-1 = 9\)):

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

Complete C# Program (A–E)

Two phases with identical inner loops; the second phase starts at D to avoid duplicating the E row.

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();

            // Top half: A through E
            for (int i = 0; i <= 4; i++)
            {
                for (int j = 4; j >= 0; j--)
                {
                    if (i == j) Console.Write(alpha[j]);
                    else Console.Write(" ");
                }
                for (int k = 1; k <= 4; k++)
                {
                    if (i == k) Console.Write(alpha[k]);
                    else Console.Write(" ");
                }
                Console.WriteLine();
            }

            // Bottom half: D through A (avoid repeating E row)
            for (int i = 3; i >= 0; i--)
            {
                for (int j = 4; j >= 0; j--)
                {
                    if (i == j) Console.Write(alpha[j]);
                    else Console.Write(" ");
                }
                for (int k = 1; k <= 4; k++)
                {
                    if (i == k) Console.Write(alpha[k]);
                    else Console.Write(" ");
                }
                Console.WriteLine();
            }
        }
    }
}

🧠 How It Works

1

Reuse the inverted-V row logic

Each row prints a left diagonal via a reverse scan (E..A) and a right diagonal via a forward scan (B..E).

Logic
2

Top half grows A..E

Outer loop prints rows for A through E.

Top
3

Bottom half mirrors D..A

Start at D so the widest E row is not duplicated.

Mirror
=

Top + mirror = diamond

Build the top half from A to E, then mirror back down from D to A.

2

Variation — Choose the Top Letter

Let the user choose the end letter (like E). Build the top half (A..end) then mirror back (end-1..A).

C#
using System;

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

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

            for (int i = 0; i <= n; i++)
            {
                for (int j = n; j >= 0; j--)
                    Console.Write(i == j ? alpha[j] : ' ');
                for (int k = 1; k <= n; k++)
                    Console.Write(i == k ? alpha[k] : ' ');
                Console.WriteLine();
            }

            for (int i = n - 1; i >= 0; i--)
            {
                for (int j = n; j >= 0; j--)
                    Console.Write(i == j ? alpha[j] : ' ');
                for (int k = 1; k <= n; k++)
                    Console.Write(i == k ? alpha[k] : ' ');
                Console.WriteLine();
            }
        }
    }
}

💡 Tips for Enhancement

Try These

  • Use dots instead of spaces to debug alignment
  • Print a trailing space to make width visible in proportional viewers
  • Combine both halves into one loop using an index mapping
  • Compare with Program 33 (top half only)

Avoid

  • Starting the bottom half at end (duplicates the widest row)
  • Using a proportional font when checking alignment
  • Allowing input beyond Z without validation

Key Takeaways

1

Diamond = top half + mirrored bottom half.

2

Bottom half starts at D to avoid duplicate center.

3

Width and rows are both 2n-1.

4

Total work is O(n²).

❓ Frequently Asked Questions

The widest row (E) is already printed at the end of the top half. Starting from D avoids duplicating that middle row.
Yes. Program 34 is program 33 printed for A..E and then mirrored back for D..A using the same inner loops.
O(n²) for n letters because there are O(n) rows and each row scans O(n) positions.

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