Inverted V-Shaped Alphabet Pattern in C#

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

What You’ll Learn

This pattern draws an inverted V: one A at the top, then pairs like B B, C C, and so on, widening as you go down.

We scan a fixed-width row and print letters only where the row index matches the current column index.

⭐ Pattern Output

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

Output
    A
   B B
  C   C
 D     D
E       E
1

Complete C# Program (A–E)

Left scan runs from E..A, then right scan runs from B..E.

C#
using System;

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

            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();
            }
        }
    }
}

🧠 How It Works

1

Each row chooses a letter

Row index i runs 0..4, representing A.. E.

Rows
2

Left leg (reverse scan)

Scan j = E..A. Print the letter only when i == j; otherwise print a space.

Left
3

Right leg (skip A)

Scan k = B..E. Skipping A ensures the first row prints only one A.

Right
=

Two slanted sides

Letters appear only when the current row matches a diagonal position; everything else is a space.

2

Variation — Choose the Top Letter

Let the user choose the end letter (like E). The left scan is end..A and the right scan is B..end.

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();
            }
        }
    }
}

💡 Tips for Enhancement

Try These

  • Use a dot (.) instead of spaces to debug alignment
  • Increase the letter range for a larger inverted V
  • Print with a trailing space to visualize the fixed width
  • Compare with Program 31 for the normal V

Avoid

  • Starting the right block at A (it would print two A’s on the first row)
  • Using a proportional font when checking alignment
  • Accepting input beyond Z without validation

Key Takeaways

1

Two diagonals form the inverted V shape.

2

Skip A in the right scan to print one A at the top.

3

Width is 2n-1 for n letters.

4

Total work is O(n²).

❓ Frequently Asked Questions

Because the right scan starts from B, so it can’t match A. Only the left scan prints A on the top row.
Program 31 is a normal V (wide at the top and one vertex at the bottom). Program 33 starts narrow and widens downward (inverted V).
O(n²) for n rows, since 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