A reverse alphabet decreasing triangle prints each row backward down to A, while the starting letter moves one step earlier each row — so the left edge slides inward.
Remember
Rule: for start letter i from last down to A,
print i down through A
EDCBA
DCBA
CBA
BA
A ← 5 rows (every row ends at A)
Same widths as Program 6 (5, 4, 3, 2, 1), but Program 6 prints forward to a fixed end (ABCDE, BCDE, …). Here both loops decrement. Compare with Program 8, which keeps E fixed on the left and shortens the tail.
Approach
How to Solve It
Two ways to emit the same shape — start with nested char loops, then optionally reverse a prefix once and slice.
Method
Idea
Best for
Nested char loops
Outer = lowering start; inner = start..A downward
Learning, interviews, exams
Reverse + Substring(i)
Build EDCBA… once, drop one left letter each row
Shorter demos once loops click
Pseudocode
Pseudocode
for start from lastLetter down to 'A':
for ch from start down to 'A':
print ch (no newline)
print newline
Change the row count and the reverse decreasing triangle updates instantly — capped at 26 letters (A–Z).
Whole numbers from 1 to 26. Tap a chip or type a value — the preview redraws as you go.
Live result5 rows · 15 letters
EDCBA
DCBA
CBA
BA
A
Trace
Worked Walkthrough — rows = 4
Trace each outer-loop start letter as i counts down from 'D' to 'A'.
Start i
Inner j
Printed row
Letters
'D'
D..A
DCBA
4
'C'
C..A
CBA
3
'B'
B..A
BA
2
'A'
A..A
A
1
Total letter prints: 4 + 3 + 2 + 1 = 10 = 4×5/2 — same triangular count as Programs 1 and 6.
Code
C# Programs
Three complete programs: fixed top letter, console input, and a reverse-Substring shortcut. Use View Output to reveal sample results.
Example 1 — Fixed from 'E' down to 'A'
Hard-coded top letter — both loops decrement; every row ends at A.
C#
using System;
class Program
{
static void Main()
{
for (char i = 'E'; i >= 'A'; i--)
{
for (char j = i; j >= 'A'; j--)
{
Console.Write(j);
}
Console.WriteLine();
}
}
}
Output
EDCBA
DCBA
CBA
BA
A
How It Works
1. Outer loop picks the start letter.i runs from 'E' down to 'A' — longest row first.
2. Inner loop walks down to A. For each start, j runs from i down to 'A', so the row is i..A in reverse.
3. Print letters, then break the line.Console.Write(j) stays on the row; WriteLine() after the inner loop starts the next (shorter) row.
When i = 'E' you get EDCBA; when i = 'A' you get A.
Example 2 — User Input Version
Read the row count at runtime. Prefer int.TryParse and clamp to 26 (shown in the tip below).
C#
using System;
class Program
{
static void Main()
{
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 >= 'A'; j--)
{
Console.Write(j);
}
Console.WriteLine();
}
}
}
Output (when user enters 4)
Enter the number of rows: 4
DCBA
CBA
BA
A
How It Works
1. Prompt and read. Ask for a row count, then convert the line to an int.
2. Map rows to a top letter.top = (char)('A' + rows - 1) — for rows = 4, top is 'D'.
3. Same reverse-shrink core. Only the source of top changes — the print logic matches Example 1.
4. Safer input tip.Convert.ToInt32 throws on letters. Prefer:
Safer input
if (!int.TryParse(Console.ReadLine(), out int rows) || rows < 1 || rows > 26)
{
Console.WriteLine("Enter a whole number from 1 to 26.");
return;
}
Example 3 — Reverse + Substring(i)
Build the first reverse row once, then drop one left letter each time — same shape, no nested letter loop.
C#
using System;
class Program
{
static void Main()
{
int rows = 5;
string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char[] arr = letters.Substring(0, rows).ToCharArray();
Array.Reverse(arr);
string top = new string(arr);
for (int i = 0; i < rows; i++)
{
Console.WriteLine(top.Substring(i));
}
}
}
Output
EDCBA
DCBA
CBA
BA
A
How It Works
1. Take and reverse the prefix.ABCDE reversed becomes EDCBA — the first printed row.
2. Slice from index i.Substring(0) is the full row; Substring(1) drops E; and so on down to A.
3. Learn loops first. Use Examples 1–2 when you need to show nested bounds; treat this as a polish shortcut afterward.
Edge Cases & Pitfalls
Check these before calling the solution done.
j++
Program 6 by mistake
If the inner loop increments instead of decrements, you print forward suffixes. Use for (char j = i; j >= 'A'; j--).
Fixed start
Program 8 shape
If the outer loop stays on 'E' and only shortens the stop, you get EDCBA, EDCB, … Advance (lower) the start with i--.
WriteLine inside
Column of letters
If WriteLine is inside the inner loop, each letter lands on its own line. Use Write for letters; WriteLine only after the inner loop.
rows > 26
Past Z
'A' + rows - 1 leaves A–Z when rows > 26. Clamp or reject in interactive programs.
rows = 1
Single A
Output is just A — start and end coincide. A good sanity check.
Bad input
Use TryParse
Convert.ToInt32 throws on letters — prefer int.TryParse and require 1–26.
Analysis
Time and Space Complexity
Program
Time
Extra space
Nested loops (Examples 1–2)
O(rows²)
O(1)
Reverse + Substring (Example 3)
O(rows²)
O(rows) for the reversed prefix and temporary row strings
Total letters = n + (n - 1) + … + 1 = n(n + 1)/2 — quadratic in n. Same totals as Programs 1 and 6.
Remember
Key Takeaways
Rule: lower start letter i; print i down through A each row.
vs Program 6: same widths — here letters run backward to A; there they run forward to a fixed end.
Break the row: call WriteLine only after the inner loop.
Complexity:O(n²) time from the triangular letter count; O(1) extra space for nested loops.
One line: for i from the top letter down to 'A', print i down through A, then WriteLine.
Frequently Asked Questions
The outer loop picks the starting letter (E, then D, then C…). The inner loop prints from that start down to A. Each row drops the previous leftmost letter and becomes shorter.
The outer loop decreases the starting letter each row, and the inner loop decreases letters within that row down to A. That matches the reverse-alphabet output.
Because the inner loop condition includes j == 'A', so the final character printed on each row is always A.
Program 6 prints forward suffixes ending at E (ABCDE, BCDE, …). This pattern prints reverse runs ending at A (EDCBA, DCBA, …). Same shrinking widths; opposite letter direction.
Program 8 always starts each row at E and shortens the tail (EDCBA, EDCB, EDC). Program 7 changes the first letter each row (E, then D, then C…).
Console.Write stays on the same line. Console.WriteLine ends the current line. Letters use Write; the row break uses WriteLine after the inner loop.
O(n²) for n rows, because total printed characters are n(n+1)/2.
Prefer int.TryParse(Console.ReadLine(), out rows) and clamp rows between 1 and 26 so bad input does not throw FormatException or walk past Z.
🤔
Did you know?
Both loops run backward: the outer loop lowers the start letter; the inner loop prints down to A. For 5 rows: EDCBA, DCBA, CBA, BA, A. Same widths as Program 6, opposite letter direction.