Reverse Alphabet, Diagonal * in C#

What You’ll Learn
Print the reverse alphabet line EDCBA on every row, but replace one character per row with * on the diagonal where i == j.
The star slides from right to left: EDCB*, EDC*A, ED*BA, E*CBA, *DCBA.
⭐ Pattern Output
EDCB*
EDC*A
ED*BA
E*CBA
*DCBAComplete C# Program
Outer i runs A..E. Inner j runs E..A. When i == j, print *; otherwise print j.
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
for (char i = 'A'; i <= 'E'; i++)
{
for (char j = 'E'; j >= 'A'; j--)
{
if (i == j)
Console.Write("*");
else
Console.Write(j);
}
Console.WriteLine();
}
}
}
}🧠 How It Works
Outer loop chooses the diagonal letter
i takes A, B, C, D, E across rows.
Inner loop prints E..A
j runs from E down to A, so the default row is EDCBA.
Replace diagonal with *
When i == j, print *. That happens at a different column each row, shifting the star.
One star per row
This is a 5×5 grid pattern, so the total work is O(n²) for n letters.
Variation — User Input Version
Read the top letter (like E) and generate the same pattern for A..top. (Cap at Z if desired.)
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter the top letter (like E): ");
char top = Convert.ToChar(Console.ReadLine());
for (char i = 'A'; i <= top; i++)
{
for (char j = top; j >= 'A'; j--)
{
Console.Write(i == j ? '*' : j);
}
Console.WriteLine();
}
}
}
}💡 Tips for Enhancement
Try These
- Replace
*with another symbol like# - Print
ABCDEinstead by making the inner loop go forward - Compare with Program 16 (centering using spaces)
- Use lowercase by switching to
'a'..
Avoid
- Using different bounds for i and j (diagonal won’t line up)
- Forgetting that inner loop direction controls whether output is E..A or A..E
- Letting ranges exceed the alphabet without planning (beyond Z)
Key Takeaways
Inner loop prints reverse letters (E..A).
i == j marks one diagonal cell per row.
Star shifts one column each row.
Complexity is O(n²).
❓ Frequently Asked Questions
i == j, so each row replaces exactly one character at the matching column."*" with any symbol (like "#" or "@") in the conditional branch.12 people found this page helpful
