Reverse Repeating-Letter Triangle in C

What You’ll Learn
Same repeating idea as program 9, but letters run E → D → C → B → A while row widths still grow 1, 2, 3, 4, 5.
Use ch = 'E' - i + 1 at the start of each outer iteration (for five rows ending at E).
⭐ Pattern Output
For 5 rows:
E
DD
CCC
BBBB
AAAAAComplete C Program (Fixed Rows)
'E' - i + 1 is equivalent to (char)('E' - (i - 1)): row 1 uses E, row 2 uses D, and so on.
#include <stdio.h>
int main() {
int i, j;
char ch;
for (i = 1; i <= 5; ++i) {
ch = (char)('E' - i + 1);
for (j = 1; j <= i; ++j) {
printf("%c", ch);
}
printf("\n");
}
return 0;
}🧠 How It Works
Outer loop: row i
i runs 1 to 5. Row i always prints i characters, so the shape is a growing triangle of repeats, same geometry as other “one letter per row” examples.
ch = 'E' - i + 1
At the start of each outer iteration you derive the letter from i and the fixed top letter E. For i = 1 you get E; for i = 5 you get A. No persistent ch++ is needed.
Inner loop: repeat the derived letter
printf("%c", ch) runs i times. Because ch is recomputed from i at the top of the outer body, each full row stays one solid letter.
New line only
printf("\n") ends the row. The next i changes both the repeat count and the letter from the same formula, so letters descend E → D → … while the row grows wider.
Formula vs. stepping ch
Two valid styles: keep one ch and increment it each row, or compute ch from i and a ceiling letter. Both yield n(n+1)/2 prints and O(n²) nested loops for n rows.
Variation — User Input Version
startChar = 'A' + rows - 1 is the top letter (E when rows == 5). Then ch = startChar - i + 1.
#include <stdio.h>
int main() {
int rows, i, j;
char ch;
int startChar;
printf("Enter the number of rows: ");
scanf("%d", &rows);
startChar = 'A' + rows - 1;
for (i = 1; i <= rows; ++i) {
ch = (char)(startChar - i + 1);
for (j = 1; j <= i; ++j) {
printf("%c", ch);
}
printf("\n");
}
return 0;
}💡 Tips for Enhancement
Try These
- Forward repeat triangle:
ch = (char)('A' + i - 1)— program 9 - Inverted widths with repeats (e.g. EEEEE, DDDD, …) by changing the outer loop over
i - Lowercase: shift
startCharwith'a'
Avoid
- Using
ch++and this formula in the same loop unless you mean to combine ideas - Rows so large that
startChar - i + 1drops below'A'unintentionally
Key Takeaways
ch = top - i + 1 gives descending letters for row indices 1…n.
Inner loop still only repeats; it does not pick the letter.
O(n²) characters for n rows.
Dual of program 9: ascending letters vs descending letters, same triangle shape.
❓ Frequently Asked Questions
'E' and i combine arithmetically, then the result is stored in ch. For i = 1..5 you get E, D, C, B, A.startChar = 'A' + rows - 1, then ch = startChar - i + 1 for i = 1..rows.Explore More C Alphabet Patterns!
One formula on ch often replaces several manual updates.
'E' - i + 1 equals 'A' + (5 - i) for five rows—same letters, two ways to think about it.
12 people found this page helpful
