Inverted V-Shaped Alphabet Pattern in C#

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\)):
A
B B
C C
D D
E EComplete C# Program (A–E)
Left scan runs from E..A, then right scan runs from B..E.
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
Each row chooses a letter
Row index i runs 0..4, representing A.. E.
Left leg (reverse scan)
Scan j = E..A. Print the letter only when i == j; otherwise print a space.
Right leg (skip A)
Scan k = B..E. Skipping A ensures the first row prints only one A.
Two slanted sides
Letters appear only when the current row matches a diagonal position; everything else is a space.
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.
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
Zwithout validation
Key Takeaways
Two diagonals form the inverted V shape.
Skip A in the right scan to print one A at the top.
Width is 2n-1 for n letters.
Total work is O(n²).
❓ Frequently Asked Questions
B, so it can’t match A. Only the left scan prints A on the top row.12 people found this page helpful
