Right-Aligned Reverse Alphabet Pyramid in C

What You’ll Learn
Companion to program 22: same fixed-width grid (" " and %2c), but each row prints a descending slice E down to the current row letter instead of a forward k++ stream.
Use a monospace font in the terminal so columns stay even.
⭐ Pattern Output
Five rows from 'E' down to 'A':
E
E D
E D C
E D C B
E D C B AComplete C Program ('A'–'E')
Character literals; equivalent to the reference using 69, 65, etc.
#include <stdio.h>
int main() {
int i, j;
for (i = 'E'; i >= 'A'; --i) {
for (j = 'A'; j < i; ++j) {
printf(" ");
}
for (j = 'E'; j >= i; --j) {
printf("%2c", j);
}
printf("\n");
}
return 0;
}🧠 How It Works
Outer i: E → A
Top row is only E; bottom row prints the full reverse run E D C B A.
Padding j < i
For i = 'E', j runs A…D: four times → eight spaces. For i = 'A', the loop body does not run.
Letters E ↓ i
printf("%2c", j) prints each letter in a width-2 field; j counts down so the segment reads E, E D, …
Row width
Padding pairs plus letter cells still fill a ten-column line for five letters (same grid as program 22).
Check
At i = 'C', two padding pairs then three %2c letters: E D C.
Variation — User Input
endChar = (char)('A' + rows - 1); outer i runs endChar down to 'A'.
#include <stdio.h>
int main() {
int rows;
int i, j;
char startChar, endChar;
printf("Enter the number of rows: ");
scanf("%d", &rows);
startChar = 'A';
endChar = (char)('A' + rows - 1);
for (i = endChar; i >= startChar; --i) {
for (j = startChar; j < i; ++j) {
printf(" ");
}
for (j = endChar; j >= i; --j) {
printf("%2c", j);
}
printf("\n");
}
return 0;
}💡 Tips for Enhancement
Try These
- Mirror program 22: start at
'Z'for a taller pyramid if it fits the console - Swap to
printf(" %c", j)and single-space padding after you count columns - Print lowercase by offsetting
startChar/endChar
Avoid
- Mixing one-space padding with
%2cwithout re-checking alignment - Forgetting that
jinprintf("%2c", j)must stay in range for a printable row
Key Takeaways
The space loop runs i - 'A' times (4 down to 0 as i goes E → A), so the first printed row has the most padding and the fewest letters.
The letter loop always ends at the current i, so the visible suffix is E … i.
%2c keeps each letter column two characters wide, matching " " padding.
O(n²) work for n rows.
❓ Frequently Asked Questions
for (i = 69; i >= 65; i--) with the same inner bounds behaves the same; literals are just clearer for humans.k across the whole figure. Here each row reuses values from E downward through i via the second inner loop.Explore More C Alphabet Patterns!
Descending outer loops plus a dedicated padding loop are a standard way to right-align triangular text.
Letters printed on the row for outer i count 'E' - i + 1; summed over i = E … A that is again 1 + 2 + … + 5 = 15 characters, like program 22.
12 people found this page helpful
