Reverse Centered Alphabet Pyramid in C

What You’ll Learn
This reverse centered alphabet pyramid reuses the row logic from program 28: run it while i steps down to 'A', then again while i steps up from 'B', so the middle line is not duplicated.
⭐ Pattern Output
Nine rows for 'A'…'E' (five down, four up after the center):
E E E E E E E E E
E D D D D D D D E
E D C C C C C D E
E D C B B B C D E
E D C B A B C D E
E D C B B B C D E
E D C C C C C D E
E D D D D D D D E
E E E E E E E E EComplete C Program ('A'–'E')
Two phases share the same pair of inner loops.
#include <stdio.h>
int main() {
int i, j;
char k = 'E';
for (i = k; i >= 'A'; --i) {
for (j = k; j >= 'A'; --j) {
if (j > i) {
printf("%c ", j);
} else {
printf("%c ", i);
}
}
for (j = 'B'; j <= k; ++j) {
if (j > i) {
printf("%c ", j);
} else {
printf("%c ", i);
}
}
printf("\n");
}
for (i = 'B'; i <= k; ++i) {
for (j = k; j >= 'A'; --j) {
if (j > i) {
printf("%c ", j);
} else {
printf("%c ", i);
}
}
for (j = 'B'; j <= k; ++j) {
if (j > i) {
printf("%c ", j);
} else {
printf("%c ", i);
}
}
printf("\n");
}
return 0;
}🧠 How It Works
Upper half: i from E down to A
Each row is a full-width “floor” line: print spaces while a column index is above the floor letter i, print descending letters on the left side of the floor, the floor letter in the middle gap, then mirror letters ascending on the right. That matches the same nested-loop idea as the hollow square alphabet pattern, but repeated for every floor level.
Center row at i == 'A'
The middle line is the widest inner sentence: E D C B A B C D E. Here the floor is A, so the left and right ramps meet with a single A between the descending and ascending halves.
Lower half: i from B back to E
A second outer loop runs the same inner structure with i increasing. That rebuilds the upper rows in reverse order so the pyramid completes without duplicating the widest E border twice.
Nine symbol rows for five letters
Each printed line contains nine letter tokens (plus spaces from printf(" ")). You get 2 × 5 - 1 = 9 text rows: five steps down to the A floor, then four steps back up to the outer E frame.
Symmetry
The fifth and sixth rows differ only in the center run A vs B.
Variation — User Input
rows is the span from 'A' to endChar; lower loop i from startChar + 1 to k.
#include <stdio.h>
int main() {
int rows;
int i, j;
char k;
char startChar, endChar;
printf("Enter the number of rows: ");
scanf("%d", &rows);
startChar = 'A';
endChar = (char)('A' + rows - 1);
k = endChar;
for (i = k; i >= startChar; --i) {
for (j = k; j >= startChar; --j) {
if (j > i) {
printf("%c ", j);
} else {
printf("%c ", i);
}
}
for (j = startChar + 1; j <= k; ++j) {
if (j > i) {
printf("%c ", j);
} else {
printf("%c ", i);
}
}
printf("\n");
}
for (i = startChar + 1; i <= k; ++i) {
for (j = k; j >= startChar; --j) {
if (j > i) {
printf("%c ", j);
} else {
printf("%c ", i);
}
}
for (j = startChar + 1; j <= k; ++j) {
if (j > i) {
printf("%c ", j);
} else {
printf("%c ", i);
}
}
printf("\n");
}
return 0;
}💡 Tips for Enhancement
Try These
- Extract one row into a function to avoid duplicating the two inner loops
- Hollow variant: print the shell letters only at the true border
- Shrink width with
%conly if you drop the trailing space
Avoid
- Starting the second phase at
'A'(reprints the center row) - Forgetting that
rowsis the span from'A'to the peak letter (total printed rows are2 × rows - 1), not a single-phase row count
Key Takeaways
Program 29 = program 28 row logic extended with a return phase (down phase + up phase) for the full pyramid.
Second phase starts at 'B' to skip the duplicate A center line.
Total rows = 2 × rows - 1 when rows counts A…endChar.
O(n²) characters for alphabet span n.
❓ Frequently Asked Questions
i reverses at the center. Splitting the phases matches how people describe “upper half” and “lower half” and keeps the B start explicit.n letters from A, you have 2n - 1 rows and 2n - 1 outputs per row, so (2n - 1)² letter prints.r to i with i = k - r for r in the first half and a symmetric map below the center. Two loops are easier to read next to program 28.A to the peak letter.Explore More C Alphabet Patterns!
Composing a known row routine twice with a shifted range is a simple way to close the reverse centered pyramid.
For n letters from A, you print 2n - 1 rows and (2n - 1)² letter prints in the reference layout.
12 people found this page helpful
