Triangle with Reverse Starting Letter in C#

What You’ll Learn
This pattern mixes ideas from program 1 and program 2: each row is longer than the last, the first letter moves backward (E, D, C, ...), but along the row letters still run forward (D then E, C then D then E, ...).
With five rows, you get E, DE, CDE, BCDE, ABCDE.
⭐ Pattern Output
For 5 rows:
E
DE
CDE
BCDE
ABCDEComplete C# Program
Outer loop chooses the first letter on the row; inner loop prints forward up to 'E'.
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
for (char i = 'E'; i >= 'A'; i--)
{
for (char j = i; j <= 'E'; j++)
{
Console.Write(j);
}
Console.WriteLine();
}
}
}
}🧠 How It Works
Outer loop: move the start
i runs from 'E' down to 'A'. That makes each row start one letter earlier.
Inner loop: print forward
For each row, j runs from i up to 'E'. So row i prints i, i+1, ..., 'E'.
New line
Console.WriteLine() ends the row and moves to the next line.
Reverse start, forward run
Total printed characters are 1+2+…+n, so time complexity is O(n²).
Variation — User Input Version
Read the number of rows and compute the right-edge letter top 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 = i; j <= top; j++)
{
Console.Write(j);
}
Console.WriteLine();
}
}
}
}💡 Tips for Enhancement
Try These
- Validate input with
int.TryParsebefore computingtop - Switch
topto a fixed letter (like'Z') to shift the whole pattern - Use lowercase by starting from
'a'instead of'A' - Compare with Program 2 (descending along each row)
Avoid
- Confusing this with the reverse-row pattern (that one uses
j--) - Letting
rowsexceed 26 without handling characters beyond'Z' - Forgetting
Console.WriteLine()after each row
Key Takeaways
The row’s first letter moves backward (E, D, C, …), but letters on the row move forward.
Using j from i to top keeps the right edge fixed at top.
Complexity is O(n²) for n rows.
This is different from Program 2 because the inner loop increments (j++), not decrements.
❓ Frequently Asked Questions
top (E in the fixed example), so the last printed character is always that same letter.j--.Explore More C# Alphabet Patterns!
Mix forward and reverse loops to build new letter patterns quickly.
If the row starts at top - k and prints \(k+1\) letters forward, the last letter is always top. That’s why the right edge stays aligned.
12 people found this page helpful
