Inverted Right-Angled Alphabet Triangle in C#

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:
ABCDE
ABCD
ABC
AB
AComplete 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.
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
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.
Inner loop always starts at A
For each row, j starts at 'A' and goes up to i, so every row begins with A.
New line
Console.WriteLine() ends the row before the next (shorter) row prints.
Inverted triangle
Total printed characters are still 1+2+…+n, so time complexity is O(n²) for n rows.
Variation — User Input Version
Read the number of rows and compute the top letter as 'A' + rows - 1:
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.TryParsebefore usingrows - 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
topshould be'A' + rows - 1in the variable-row version - Letting
rowsexceed 26 without handling letters beyond'Z' - Skipping
Console.WriteLine()after each row
Key Takeaways
Counting the outer loop down makes the triangle inverted (rows shrink).
Starting the inner loop at 'A' resets the alphabet for every row.
Complexity remains O(n²) for n rows.
This is the inverted companion to Program 1 (growing rows).
❓ Frequently Asked Questions
j = 'A', so every row prints an A-prefixed sequence.Explore More C# Alphabet Patterns!
Inverted shapes are a small loop change away from the standard triangle.
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.
12 people found this page helpful
