An inverted repeating alphabet triangle prints a wide first row of one letter, then shrinks by one repeated letter on each new line while letters count down.
Remember
Rule: for letter i from top down to 'A',
print i exactly (i - 'A' + 1) times
EEEEE
DDDD
CCC
BB
A ← 5 rows (top = 'E')
It is the flip of Program 10: same countdown letters, but widths shrink 5, 4, 3, …, 1 instead of growing. Print the outer letter inside the inner loop so each row stays uniform.
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; inner = width; print outer letter
Learning, interviews, exams
new string(ch, repeat)
Build a whole repeated-letter row in one call
Shorter demos once loops click
Pseudocode
Pseudocode
for i from top down to 'A':
for j from 'A' to i:
print i (no newline)
print newline
Change the height and the inverted triangle updates instantly — including the letter total.
Whole numbers from 1 to 26 (A–Z). Tap a chip or type a value — the preview redraws as you go.
Live result5 rows · 15 letters
EEEEE
DDDD
CCC
BB
A
Trace
Worked Walkthrough — 'E' down to 'A'
Trace each outer-loop value of i and count how many times the inner loop runs.
i
Inner j range
Printed row
Repeats
'E'
'A'..'E'
EEEEE
5
'D'
'A'..'D'
DDDD
4
'C'
'A'..'C'
CCC
3
'B'
'A'..'B'
BB
2
'A'
'A'..'A'
A
1
Total letter prints: 5 + 4 + 3 + 2 + 1 = 15 = 5×6/2. That triangular sum is why time is O(n²).
Code
C# Programs
Three complete programs: fixed letters, console input, and a new string shortcut. Use View Output to reveal sample results.
Example 1 — Fixed 'E' down to 'A'
Hard-coded range — outer letter counts down; inner loop shrinks and prints that letter.
C#
using System;
class Program
{
static void Main()
{
for (char i = 'E'; i >= 'A'; i--)
{
for (char j = 'A'; j <= i; j++)
{
Console.Write(i);
}
Console.WriteLine();
}
}
}
Output
EEEEE
DDDD
CCC
BB
A
How It Works
1. Outer loop picks the letter.i runs from 'E' down to 'A'.
2. Inner loop sets the width.j runs from 'A' to i — five times for E, four for D, and so on.
3. Print the outer letter.Console.Write(i) keeps the whole row the same character.
4. Break the line.Console.WriteLine() after the inner loop starts the next row.
Example 2 — User Input Version
Compute top = 'A' + rows - 1, then shrink with repeat = ch - 'A' + 1. Prefer int.TryParse in real apps.
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 ch = top; ch >= 'A'; ch--)
{
int repeat = ch - 'A' + 1;
for (int k = 1; k <= repeat; k++)
{
Console.Write(ch);
}
Console.WriteLine();
}
}
}
Output (when user enters 4)
Enter the number of rows: 4
DDDD
CCC
BB
A
How It Works
1. Prompt and read. Ask for a row count, then convert the line to an int.
2. Compute the top letter. For rows = 4, top is 'D' — first row is DDDD.
3. Same shrink core.repeat = ch - 'A' + 1 gives widths 4, 3, 2, 1 as ch counts down.
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 — new string(ch, repeat)
Build each repeated-letter row in one call — same shape, no explicit character loop.
C#
using System;
class Program
{
static void Main()
{
int rows = 5;
char top = (char)('A' + rows - 1);
for (char ch = top; ch >= 'A'; ch--)
{
int repeat = ch - 'A' + 1;
Console.WriteLine(new string(ch, repeat));
}
}
}
Output
EEEEE
DDDD
CCC
BB
A
How It Works
1. Same countdown. Still walk ch from top down to 'A'.
2. Build the row.new string(ch, repeat) creates a string of length repeat filled with ch.
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.
Write(j)
Stepping letters on a row
If you print j instead of i, you get ABCDE on the first row. Print the outer letter to keep each row uniform.
i++
Growing triangle by mistake
Counting letters upward with growing widths reprints Program 10’s shape family. Keep i-- from the top letter down to 'A'.
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 — top and tip 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)
new string (Example 3)
O(rows²)
O(rows) per temporary row string
Total letters = n + (n - 1) + … + 1 = n(n + 1)/2 — still quadratic in n. Same totals as Program 10; only the print order of widths differs.
Remember
Key Takeaways
Rule: countdown letter i; print i exactly i - 'A' + 1 times.
Flip of Program 10: same letters — widths shrink instead of grow.
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 for every j from 'A' to i, then WriteLine.
Frequently Asked Questions
Program 10 prints widths 1..5 (E, DD, CCC, ...). Program 11 prints widths 5..1 (EEEEE, DDDD, ...). Both use repeating letters per row and letters counting down.
When i is E, the inner loop runs from A through E (5 times) and prints E each time. Next i becomes D, the inner loop runs 4 times (A..D) and prints D.
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 stops at j <= i. Smaller i means fewer iterations, so fewer characters are printed.
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 inverted twin of Program 10: letters still step E→A, but widths shrink 5, 4, 3, …, 1 instead of growing. Print the outer loop letter inside the inner loop so each row stays uniform.