Right-Aligned Reverse Alphabet Pyramid in C#

What You’ll Learn
Companion to Program 22: same fixed-width grid (two spaces for padding + {0,2} for letters), but each row prints a reverse alphabet slice E down to the current row letter.
Use a monospace terminal so columns stay aligned.
⭐ Pattern Output
Five rows from E down to A:
E
E D
E D C
E D C B
E D C B AComplete C# Program (A–E)
First print padding pairs, then print letters from E down to the current row letter.
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
for (char i = 'E'; i >= 'A'; i--)
{
for (char j = 'A'; j < i; j++)
Console.Write(" ");
for (char j = 'E'; j >= i; j--)
Console.Write("{0,2}", j);
Console.WriteLine();
}
}
}
}🧠 How It Works
Outer loop descends from E to A
Top row has one letter (E); each next row grows by one letter until E D C B A.
Padding loop shifts the block
For j = A..(i-1) we print " ". When i is E we print 4 padding cells; when i is A, we print 0.
Letter loop prints a reverse slice
Second inner loop prints j = E..i, using {0,2} to keep each letter 2 columns wide.
Right-aligned growth
Two inner loops keep the block aligned while it grows by one letter per row.
Variation — User Input Top Letter
Let the user choose the starting (top) letter. The pattern prints rows down to A.
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter the top letter (like E): ");
char top = Convert.ToChar(Console.ReadLine());
for (char i = top; i >= 'A'; i--)
{
for (char j = 'A'; j < i; j++)
Console.Write(" ");
for (char j = top; j >= i; j--)
Console.Write("{0,2}", j);
Console.WriteLine();
}
}
}
}💡 Tips for Enhancement
Try These
- Print a space after each formatted letter for extra separation
- Swap descending letters for numbers using the same padding idea
- Compare with Program 22 (uses a k++ stream)
- Center the whole shape by adding extra left padding
Avoid
- Viewing output in proportional fonts (alignment will look wrong)
- Printing one space for padding (cells become uneven)
- Changing the letter format width without changing the padding
Key Takeaways
Two loops: padding then letters.
Use fixed-width cells ({0,2}) for alignment.
Rows print a reverse slice (E..i).
Overall complexity is O(n²).
❓ Frequently Asked Questions
{0,2}). Matching the padding to that width keeps the pyramid aligned.12 people found this page helpful
