Inverted Right-Angled Alphabet Triangle in C#

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

What You’ll Learn

How to print an inverted alphabet right-angled triangle: the first row is the longest (ABCDE for five rows), and each next row removes one letter while still starting from 'A'.

This is the partner to program 1. Only the outer loop direction changes: growing vs shrinking row lengths.

⭐ Pattern Output

For 5 rows:

Output
ABCDE
ABCD
ABC
AB
A
1

Complete C# Program

Outer loop shrinks the row by decreasing the end letter from 'E' to 'A'. Inner loop always prints from 'A' up to that end 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(j);
                }
                Console.WriteLine();
            }
        }
    }
}

🧠 How It Works

1

Outer loop shrinks the width

i runs from 'E' down to 'A'. That means the first row has 5 letters and each next row has one fewer.

Row width
2

Inner loop always starts at A

For each row, j starts at 'A' and goes up to i, so every row begins with A.

Fresh prefix
3

New line

Console.WriteLine() ends the row before the next (shorter) row prints.

Line break
=

Inverted triangle

Total printed characters are still 1+2+…+n, so time complexity is 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 = top; i >= 'A'; i--)
            {
                for (char j = 'A'; j <= i; j++)
                {
                    Console.Write(j);
                }
                Console.WriteLine();
            }
        }
    }
}

💡 Tips for Enhancement

Try These

  • Validate input with int.TryParse before using rows
  • Print lowercase by using 'a' instead of 'A'
  • Switch the outer loop to count up for the growing triangle (Program 1)
  • Compare with inverted star triangles in the star-pattern series

Avoid

  • Forgetting that top should be 'A' + rows - 1 in the variable-row version
  • Letting rows exceed 26 without handling letters beyond 'Z'
  • Skipping Console.WriteLine() after each row

Key Takeaways

1

Counting the outer loop down makes the triangle inverted (rows shrink).

2

Starting the inner loop at 'A' resets the alphabet for every row.

3

Complexity remains O(n²) for n rows.

4

This is the inverted companion to Program 1 (growing rows).

❓ Frequently Asked Questions

Because the inner loop always begins with j = 'A', so every row prints an A-prefixed sequence.
See Program 1, where the outer loop increases so row lengths grow.
O(n²) for n rows.

Explore More C# Alphabet Patterns!

Inverted shapes are a small loop change away from the standard triangle.

All Alphabet Patterns →
Did you know?

If you flip only the outer loop direction between Program 1 and Program 5, you reuse the same “print from A up to a bound” inner-loop logic.

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