Reverse Triangle, E Always First in C#

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

What You’ll Learn

How to print a reverse triangle where every row begins with the same top letter (E in the 5-row example) and becomes shorter each line: EDCBA, EDCB, EDC, ED, E.

Compare program 7 (the first letter changes each row) and program 2 (different reverse-row growth rule).

⭐ Pattern Output

For 5 rows:

Output
EDCBA
EDCB
EDC
ED
E
1

Complete C# Program

Outer loop raises the stopping letter; inner loop always starts at E and counts down.

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            for (char i = 'A'; i <= 'E'; i++)
            {
                for (char j = 'E'; j >= i; j--)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }
        }
    }
}

🧠 How It Works

1

Outer loop raises the floor

i runs from 'A' to 'E'. It sets how far down the inner loop should go on that row.

Lower bound
2

Inner loop always starts at E

j starts at 'E' on every row, so the first printed character is always E.

Fixed first letter
3

Shrinking tail

The condition j >= i makes the row shorter each time: when i is A, you print down to A; when i is E, you print only E.

5 … 1
=

Mixed directions

Outer i++ and inner j-- together control the clipping. Total work is still O(n²) for n rows.

2

Variation — User Input Version

Read the number of rows and compute the top letter as 'A' + rows - 1:

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter the number of rows: ");
            int rows = Convert.ToInt32(Console.ReadLine());

            char top = (char)('A' + rows - 1);
            for (char i = 'A'; i <= top; i++)
            {
                for (char j = top; j >= i; j--)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }
        }
    }
}

💡 Tips for Enhancement

Try These

  • Validate input with int.TryParse before using rows
  • Try lowercase using 'a' and 'a' + rows - 1
  • Compare with Program 7 (first letter changes each row)
  • Add spaces between letters for readability

Avoid

  • Using j >= 'A' when you want shrinking rows (that would print full width every time)
  • Letting rows exceed 26 without handling letters beyond 'Z'
  • Forgetting Console.WriteLine() after each row

Key Takeaways

1

The inner loop always starts at the top letter, so the first character is fixed.

2

The outer loop only tightens the stopping point, shortening each row.

3

Mixed increment/decrement loops are common in pattern problems.

4

Complexity is O(n²) for n rows.

❓ Frequently Asked Questions

Because the inner loop initializes j to the top letter each time, so the first output is always E.
Program 7 changes the first letter each row (E, then D, then C...). Program 8 keeps the first letter fixed and only shortens the tail.
O(n²) for n rows.

Explore More C# Alphabet Patterns!

Fixing one corner and sliding loop bounds is a great way to invent new patterns.

All Alphabet Patterns →
Did you know?

If you changed the inner condition from j >= i to j >= 'A', every row would print the full EDCBA string—no shrinking.

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