Shape Rule
Reverse slices
Rows grow: E, then E D, … E D C B A.

Companion to Program 22: same fixed-width grid (two spaces for padding + %2c for letters), but each row prints a reverse alphabet slice from the top letter down to the current row letter. Use a monospace terminal so columns stay aligned. Compare Program 20 (right-aligned reverse without fixed-width cells). Includes a live preview, worked C examples, edge cases, and complexity.
Reverse slices
Rows grow: E, then E D, … E D C B A.
Pad, then letters
Empty cells first; reverse slice second.
Width 2
Pad with " "; print letters with %2c.
E → A
Outer i descends from the top letter to A.
Top letter
Pick a top letter (A–F in the preview) and draw.
Complexity
n rows × O(n) pad + letter work.
A right-aligned reverse alphabet pyramid prints a growing reverse slice of the alphabet on each row, right-aligned with matching pad and letter cell widths.
In C you solve it with a descending char outer loop and two inner loops: padding, then letters from the top letter down to the row letter.
It shows how reverse ranges, padding counts, and format widths work together — a step beyond continuous k++ streams.
Each row prints top..i.
Pads shrink as rows grow.
" " matches %2c.
Slice per row, not a stream.
In short: for each row letter i from top down to A, print pads for A..(i-1), then letters top..i with width 2, then call printf("\n").
Given a top letter (or fixed E), print a right-aligned pyramid of reverse alphabet slices ending at A.
// Five rows (monospace; each cell is width 2)
// E
// E D
// E D C
// E D C B
// E D C B A | Item | Type | Description |
|---|---|---|
top | char | Highest letter (e.g. E). Rows run from top down to A. |
| Printed output | text | Right-aligned reverse slices in fixed-width cells. |
for i from top down to 'A':
for j from 'A' to (i - 1):
print two spaces
for j from top down to i:
print j with width 2
print newline | Approach | Idea | Best for |
|---|---|---|
| Char loops (classic) | Pad A..(i-1); letters top..i | Matching this sample |
| Int row index | n = top-'A'+1; pad n-row; letters by index | When you prefer int counters |
| Goal | Pattern |
|---|---|
| Outer rows | for (char i = top; i >= 'A'; i--) |
| Pad cells | for (char j = 'A'; j < i; j++) printf(" "); |
| Letter slice | for (char j = top; j >= i; j--) printf("%2c", j); |
| End row | printf("\n"); |
| Sequential stream | See Program 22 (k++) |
Same row — three roles that build the reverse pyramid.
pad2-column empty cells for right alignment
sliceReverse letters from top down to row letter
growEach row adds one more letter on the left of the slice
breakEnds the row after pads + letters
Reach for this when teaching reverse ranges with fixed-width alignment.
Same grid idea; reverse slices instead of a continuous stream.
Practice looping on char instead of only int.
Similar reverse right-align idea; this page stresses width-2 cells.
Match pad string length to %2c exactly.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: separate pad and reverse-letter loops make right-aligned reverse pyramids easy to read and debug.
Choose a top letter from A to F and draw the right-aligned reverse pyramid in the browser (monospace cells).
Three complete C programs — fixed A–E, scanf top letter, and an int-index style. Click View Output to reveal sample console results.
Print five right-aligned reverse rows from E down to A.
First print padding pairs, then print letters from E down to the current row letter.
#include <stdio.h>
int main() {
char 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;
} When i = 'C', pads run for A and B (two cells), then letters print E D C. Pads shrink and the reverse slice grows until the bottom row is E D C B A.
Let the user choose the starting (top) letter.
The pattern prints rows from the chosen top letter down to A. Check scanf’s return value and require A–Z in real apps.
#include <stdio.h>
int main() {
char top, i, j;
printf("Enter the top letter (like E): ");
scanf(" %c", &top);
for (i = top; i >= 'A'; --i) {
for (j = 'A'; j < i; ++j) {
printf(" ");
}
for (j = top; j >= i; --j) {
printf("%2c", j);
}
printf("\n");
}
return 0;
} Same pad/letter rules; only the shared top letter changes. Both the outer start and the letter-loop start use top.
Same shape with integer row and column indexes.
Often clearer if you think in row numbers: pad n - row cells, then print row letters from the top down.
#include <stdio.h>
int main() {
char top = 'E';
int n = top - 'A' + 1;
int row, s, k;
for (row = 1; row <= n; ++row) {
for (s = 0; s < n - row; ++s) {
printf(" ");
}
for (k = 0; k < row; ++k) {
printf("%2c", (char)(top - k));
}
printf("\n");
}
return 0;
} Row 1 prints one letter (E); row 5 prints five (E..A). Pad count is n - row; letter k is (char)(top - k).
Top row has one letter (E); each next row grows by one letter until E D C B A.
For j = A..(i-1) we print " ". When i is E we print 4 padding cells; when i is A, we print 0.
Second inner loop prints j = E..i, using %2c to keep each letter 2 columns wide.
printf("\n") ends the row so the next lower i can grow the slice.
Two inner loops keep the block aligned while it grows by one letter per row — O(n²) time.
Trace each row’s pads, reverse slice, and printed line.
i | Pad cells | Letters | Printed row |
|---|---|---|---|
E | 4 | E | ········E |
D | 3 | E D | ······E D |
C | 2 | E D C | ····E D C |
B | 1 | E D C B | ··E D C B |
A | 0 | E D C B A | E D C B A |
Row count = top - 'A' + 1 (5 for E). Each cell is 2 columns wide.
Where this reverse right-aligned pyramid shows up beyond the homework prompt.
Clearest demo of printing top..i each row.
Example: swap descending for ascending and compare.
Same fixed-width grid — stream vs reverse slice.
Example: print both for 5 rows side by side.
Outer and inner loops over char ranges.
Example: rewrite with int indexes (Example 3).
Match pad string length to letter field width.
Example: try one-space pads and watch columns break.
Growing reverse slices make O(n²) easy to see.
Example: 5 rows print 1+2+3+4+5 letter cells.
Reverse wings lead naturally into palindromic pyramids.
Example: continue to Program 24.
Pro Tip: say “pads first, then top down to the row letter” before coding — that story prevents confusing this with Program 22’s stream.
Why this pattern earns a spot after sequential right-aligned triangles.
Wrong pad count or letter direction shows up immediately.
Char loops or int indexes teach the same shape.
A natural place to learn descending char loops.
Streaming output needs no storage beyond loop variables.
Pro Tip: learn the classic char-loop version first; treat the int-index rewrite as a clarity option afterward.
Small habits that keep reverse right-aligned pyramids clean.
Use two spaces when letters use %2c.
Always begin the slice at the top letter, not at i.
Require a single A–Z character; normalize case if needed.
Proportional fonts make width-2 cells look misaligned.
If letters run A, B C, D E F… you wrote the sequential stream instead.
Pro Tip: if the first row is A instead of E, check that the outer loop starts at the top letter and the letter loop also starts there.
Mistakes that commonly break reverse right-aligned pyramids.
Rows become single letters or wrong slices.
→ Letter loop must start at top (or E), not at i.
Empty cells become narrower than %2c letter fields.
→ Print " " (two spaces) for each pad cell.
Columns look broken even when the code is correct.
→ View output in a monospace terminal/font.
scanfEmpty or non-letter input leaves top invalid.
→ Check scanf’s return value and require A–Z.
Using k++ produces A, B C, D E F… instead of reverse slices.
→ Print j from top down to i each row.
Check these inputs before calling the solution done.
Output is just A (no pads).
Five rows through E D C B A.
Three rows (Example 2).
Normalize with char.toupper if needed.
Unchecked scanf fails silently — check the return value.
Reject non A–Z tops so loops do not misbehave.
Try these variations to lock in the pattern.
i..top instead of top..i" " ↔ %2c).top - 'A' + 1 (5 for E).k++ stream across rows.Quick Takeaway: pad empty width-2 cells for A..(i-1), print reverse letters top..i with matching width, then break the line.
| Program | Time | Extra space |
|---|---|---|
| Char pad + letters (Examples 1–2) | O(n²) | O(1) |
| Int row index (Example 3) | O(n²) | O(1) |
Each of n rows does O(n) pad + letter work, so total work is O(n²).
The right-aligned reverse alphabet pyramid is a small nested-loop exercise with lasting payoff: reverse letter ranges, shrinking pads, and fixed-width cells. Master the classic E…A sample, then try user input and the int-index rewrite.
Practice the three examples above, then continue to Program 24’s palindromic alphabet pyramid.
Pad for A..(i-1), print top..i with width 2, match pad and letter widths, then break the line.
scanf and require an A–Z top letteri instead of topk++ streamprintf("\n") inside the pad or letter loopPrint the right-aligned reverse alphabet pyramid the beginner-friendly way.
Pad + reverse slice
Definitiontop..i each row
Code" " & %2c
CodeEnds each row
I/OO(n²) time
AnalysisOuter i runs from E down to A. The first inner loop prints one " " per j with A <= j < i (so the block shifts left each row). The second loop prints letters from E down to i using %2c so each cell is 2 columns wide.
Next up: palindromic alphabet pyramids.
12 people found this page helpful