An inverted forward repeating alphabet triangle shrinks in width each row while the letter advances: row 1 is all As, row 2 all Bs, and so on.
Remember
Rule: letter advances A→top; width shrinks n..1
Print the outer letter, not the inner counter
AAAAA
BBBB
CCC
DD
E ← 5 rows (A–E)
Same inverted widths as Program 11, but letters count up instead of down. Inside the inner loop, print i (the row letter), not j.
Approach
How to Solve It
Two ways to emit the same shape — start with nested char loops, then optionally shorten with new string.
Method
Idea
Best for
Nested char loops
Outer = letter A→top; inner = top down to i, print i
Learning, interviews, exams
Index + new string
ch = 'A' + row, repeat = rows - row
Shorter demos once loops click
Pseudocode
Pseudocode
top = 'A' + rows - 1
for i from 'A' to top:
for j from top down to i:
print i (no newline)
print newline
Cheat sheet
Goal
Pattern
Walk each letter
for (char i = 'A'; i <= top; i++)
Shrink the width
for (char j = top; j >= i; j--)
Uniform row letter
Console.Write(i); — not j
End the row
Console.WriteLine();
Index form
ch = (char)('A' + row), repeat = rows - row
One-line shortcut
Console.WriteLine(new string(ch, repeat));
Write vs WriteLine
API
Effect
Use for
Console.Write
Stays on the same line
Each letter on the row
Console.WriteLine
Ends the current line
After the inner loop
Try it
Live Preview
Change the row count and the inverted forward triangle updates instantly — including letter and print counts.
Whole numbers from 1 to 26 (A–Z). Tap a chip or type a value — the preview redraws as you go.
Live result5 rows · A–E · 15 letters
AAAAA
BBBB
CCC
DD
E
Trace
Worked Walkthrough — rows = 4 (A–D)
Trace each outer letter i and count how many times the inner loop prints it.
i
Inner j
Printed row
Count
A
D..A
AAAA
4
B
D..B
BBB
3
C
D..C
CC
2
D
D..D
D
1
Total letter prints: 4 + 3 + 2 + 1 = 10 = 4×5/2. That triangular sum is why time is O(n²).
Code
C# Programs
Three complete programs: fixed A–E, console input, and a new string shortcut. Use View Output to reveal sample results.
Example 1 — Fixed 'A' up to 'E'
Hard-coded range — ideal for first demos and screenshots.
C#
using System;
class Program
{
static void Main()
{
for (char i = 'A'; i <= 'E'; i++)
{
for (char j = 'E'; j >= i; j--)
{
Console.Write(i);
}
Console.WriteLine();
}
}
}
Output
AAAAA
BBBB
CCC
DD
E
How It Works
1. Outer loop picks the letter.i runs from 'A' to 'E' — that letter fills the whole row.
2. Inner loop sets the width.j runs from 'E' down to i, so widths are 5, 4, 3, 2, 1.
3. Print i, not j.Console.Write(i) keeps the row uniform (AAAAA, not EDCBA).
4. Break the line.Console.WriteLine() after the inner loop starts the next row.
Example 2 — User Input Version
Read the height at runtime. Prefer int.TryParse and clamp to 1–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());
for (int row = 0; row < rows; row++)
{
char ch = (char)('A' + row);
int repeat = rows - row;
for (int k = 1; k <= repeat; k++)
{
Console.Write(ch);
}
Console.WriteLine();
}
}
}
Output (when user enters 4)
Enter the number of rows: 4
AAAA
BBB
CC
D
How It Works
1. Prompt and read. Ask for a row count, then convert the line to an int.
2. Index form of the same shape. Row 0 prints Arows times; row 1 prints Brows - 1 times; and so on.
3. 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 — new string(ch, repeat)
Build each repeated-letter row in one call — same shape, no explicit inner print loop.
C#
using System;
class Program
{
static void Main()
{
int rows = 5;
for (int row = 0; row < rows; row++)
{
char ch = (char)('A' + row);
int repeat = rows - row;
Console.WriteLine(new string(ch, repeat));
}
}
}
Output
AAAAA
BBBB
CCC
DD
E
How It Works
1. One outer loop. Still walk row from 0 to rows - 1.
2. Build the row.new string(ch, repeat) creates a string of length repeat filled with ch.
3. Print and advance.WriteLine prints that string and ends the line.
Learn the two-loop version first (Examples 1–2) so you can explain both bounds in an interview; treat this as a polish shortcut afterward.
Edge Cases & Pitfalls
Check these before calling the solution done.
Write(j)
Stepping letters
If you print j instead of i, the first row becomes EDCBA. Always Console.Write(i) for this shape.
Countdown outer
Program 11 by mistake
Counting i from top down to A prints EEEEE first. Outer loop must advance A→top.
WriteLine inside
Column of letters
If WriteLine sits inside the inner loop, each letter lands on its own line. Call it only after the inner loop.
rows > 26
Past Z
Clamp to 1–26 so 'A' + row never walks past Z.
rows = 1
Single A
Output is just A — a good sanity check.
Bad input
Use TryParse
Convert.ToInt32 throws on letters — prefer int.TryParse.
Analysis
Time and Space Complexity
Program
Time
Extra space
Nested loops (Examples 1–2)
O(rows²)
O(1)
new string(ch, repeat) (Example 3)
O(rows²)
O(rows) per temporary row string
Total letters printed = n + (n-1) + … + 1 = n(n+1)/2, which is still quadratic in n.
Remember
Key Takeaways
Rule: letters advance A→top; widths shrink n..1.
Print i: the outer letter fills the row; j only sets the count.
Break the row:Write for letters; WriteLine after the inner loop.
Complexity:O(n²) time from the triangular letter count; O(1) extra space for nested loops.
One line: for each letter i from A to top, print i(top - i + 1) times, then WriteLine.
Frequently Asked Questions
Program 11 prints EEEEE, DDDD, ... (letters step down). Program 12 prints AAAAA, BBBB, ... (letters step up) with the same inverted widths 5..1.
When i is A, the inner loop runs from E down to A (5 times) and prints A each time. Next i becomes B, the inner loop runs 4 times (E..B) and prints B.
j only controls how many times the loop runs. Printing i keeps the entire row the same letter; printing j would step letters across the row.
Because the inner loop runs from the fixed top letter down to the current i. As i increases, the loop has fewer iterations.
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²) where n is the number of rows. Total Console.Write calls equal n+(n-1)+…+1 = n(n+1)/2.
Yes. Console.WriteLine(new string(ch, repeat)) prints a full repeated-letter row in one call. Nested loops are better for learning; the string constructor is a handy shortcut later.
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?
This is the forward-letter twin of Program 11: same inverted widths (5…1), but letters advance A→E instead of stepping down. Print the outer loop letter inside the inner loop so each row stays uniform.