Reverse Order Alphabet Triangle in C#

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

What You’ll Learn

How to print a right-angled triangle where the first character of each row moves forward (A, B, C, D, E), but each row prints letters in reverse order down to A: A, BA, CBA, DCBA, EDCBA.

Compare with program 1 (forward along each row) and program 3 (reverse starting letter, forward along row).

⭐ Pattern Output

For 5 rows:

Output
A
BA
CBA
DCBA
EDCBA
1

Complete C# Program

Outer loop picks the highest letter on each row; inner loop prints from that letter down to 'A'.

C#
using System;

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

🧠 How It Works

1

Outer loop (rows)

i runs from 'A' to 'E'. Row length grows because later rows start at a higher letter.

Row control
2

Inner loop (descending letters)

For each row, j starts at i and counts down to 'A'. Printing j produces BA, CBA, DCBA, and so on.

Reverse along row
3

New line

Console.WriteLine() ends the current row and moves to the next line.

Line break
=

Reverse-order triangle

Total printed characters are 1+2+…+n, so time complexity is O(n²).

2

Variation — User Input Version

Read the number of rows and loop i from 'A' to '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());

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

💡 Tips for Enhancement

Try These

  • Validate input with int.TryParse before using rows
  • Print lowercase by starting from 'a' instead of 'A'
  • Compare with Program 1 (forward along the row)
  • Right-align the output by printing leading spaces

Avoid

  • Using j++ in the inner loop (that would print forward, not BA/CBA)
  • Letting 'A' + rows - 1 go past 'Z' without handling it
  • Forgetting Console.WriteLine() after each row

Key Takeaways

1

The outer loop increases the row’s starting (highest) letter: A, B, C, …

2

The inner loop counts down from i to 'A' to print letters in reverse order.

3

Every row ends at 'A', so the right edge is vertical.

4

Complexity is O(n²) for n rows.

❓ Frequently Asked Questions

The inner loop always runs until j reaches 'A', so the last printed character is A for every row.
See Program 1, where the inner loop prints from 'A' up to the row’s end letter.
O(n²) for n rows because you print 1+2+…+n characters.

Explore More C# Alphabet Patterns!

Small changes in loop direction completely change the output—keep experimenting.

All Alphabet Patterns →
Did you know?

This pattern’s left edge grows A, B, C, … while the right edge stays A. It’s a neat example of how loop bounds shape the output.

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