Inverted Repeating-Letter Triangle in C

What You’ll Learn
First row: five Es. Each following row is one character shorter and uses the next letter down: EEEEE, DDDD, CCC, BB, A.
Pair with program 9 (width grows, ch++) and program 5 (inverted triangle with changing letters each column).
⭐ Pattern Output
For 5 rows:
EEEEE
DDDD
CCC
BB
AComplete C Program (Fixed Rows)
i controls width (5 down to 1). ch starts at 'E'; after each full row, move to the previous letter.
#include <stdio.h>
int main() {
int i, j;
char ch = 'E';
for (i = 5; i >= 1; --i) {
for (j = 1; j <= i; ++j) {
printf("%c", ch);
}
printf("\n");
ch--;
}
return 0;
}🧠 How It Works
ch = 'E'
The first row is the widest and uses the highest letter in the range. Each shorter row will use the next letter down the alphabet after ch--.
Outer loop i = 5 .. 1
i is both the row counter and how many times you print per row. Counting down makes the triangle invert: five Es, then four Ds, and so on.
Inner loop: one letter, many times
for (j = 1; j <= i; ++j) calls printf("%c", ch) without updating ch inside the inner loop, so the entire row shows the same character.
New line, then ch--
printf("\n") finishes the row. Decrementing ch moves backward in ASCII (E → D → C …) for the next, shorter row.
Inverted repeat triangle
You still print 5+4+3+2+1 = 15 characters for five rows. For n rows that is n(n+1)/2 prints and O(n²) nested-loop work.
Variation — User Input Version
ch = 'A' + rows - 1 picks the letter for the first (widest) row; loop i from rows down to 1.
#include <stdio.h>
int main() {
int rows, i, j;
char ch;
printf("Enter the number of rows: ");
scanf("%d", &rows);
ch = (char)('A' + rows - 1);
for (i = rows; i >= 1; --i) {
for (j = 1; j <= i; ++j) {
printf("%c", ch);
}
printf("\n");
ch--;
}
return 0;
}💡 Tips for Enhancement
Try These
- Equivalent: compute
ch = (char)('A' + i - 1)at the start of each outer step if you loopidown without mutatingch - Growing repeat triangle: program 9
- Cap
rowsor wrap ifchwould pass'A'backward past your intended range
Avoid
ch--inside the inner loop unless you want a staircase of letters- Forgetting
ch--so every row stays on'E'
Key Takeaways
Inverted outer loop (5→1) + repeat inner loop = shrinking repeated rows.
ch-- once per row keeps each line uniform.
O(n²) characters for n rows.
Natural complement to program 9 and inverted program 5.
❓ Frequently Asked Questions
i starts at 5, so the inner loop runs five times while ch is still 'E'.printf("\n") matches program 9’s style (ch++ after the newline).ch = 'A' + rows - 1, then for (i = rows; i >= 1; --i) with the same inner loop and ch--.Explore More C Alphabet Patterns!
Inverted width plus ch-- mirrors inverted stars with a letter skin.
You can derive the same output with ch = (char)('A' + i - 1) at the top of each outer iteration while i runs from rows down to 1—no persistent ch-- needed.
12 people found this page helpful
