Right-Aligned Reverse Alphabet Pyramid in C#

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

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:

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

Complete C# Program (A–E)

First print padding pairs, then print letters from E down to the current row letter.

C#
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

1

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.

Descend
2

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.

Pad
3

Letter loop prints a reverse slice

Second inner loop prints j = E..i, using {0,2} to keep each letter 2 columns wide.

Slice
=

Right-aligned growth

Two inner loops keep the block aligned while it grows by one letter per row.

2

Variation — User Input Top Letter

Let the user choose the starting (top) letter. The pattern prints rows down to A.

C#
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

1

Two loops: padding then letters.

2

Use fixed-width cells ({0,2}) for alignment.

3

Rows print a reverse slice (E..i).

4

Overall complexity is O(n²).

❓ Frequently Asked Questions

Because the letters are printed in a 2-character field ({0,2}). Matching the padding to that width keeps the pyramid aligned.
Yes. Change the second loop to always begin from your chosen top letter and decrement to the row letter.
O(n²) because each of n rows prints O(n) cells.

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