Symmetric Decreasing Alphabet Square in C#

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):
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 EComplete C# Program (A–E)
Two symmetric scans per row with the same j > i check, matching the reference logic.
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
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].
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.
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.
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.
Symmetry + layers
Each row is a symmetric “layer” around the center. As i decreases, the minimum letter moves inward (E → D → C → B → A).
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.
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
Two halves create symmetry (E..A then B..E).
Condition j > i chooses border vs interior.
Center drops to A on the last row.
Total work is O(n²).
❓ Frequently Asked Questions
k = top - 'A', and keep the same loop structure.12 people found this page helpful
