Shape Rule
Right-aligned reverse
Growing reverse suffixes sit on the right of a fixed width.

Each row is a reverse suffix (A, BA, CBA, …) padded on the left so the letters line up on the right in a fixed-width column. This is the same j > i idea as the left half of Program 19, but without the second mirror loop. Compare Program 2 (reverse, left-aligned). Includes a live preview, worked C examples, edge cases, and complexity.
Right-aligned reverse
Growing reverse suffixes sit on the right of a fixed width.
Row peak
i walks A..top so the visible suffix grows each row.
Fixed width
j always walks top down to A for every row.
j > i
Print a space while above the peak; then print letters.
Top letter
Pick A–J and draw the right-aligned pyramid instantly.
Complexity
n rows × n columns per fixed-width scan.
A right-aligned reverse alphabet pyramid keeps every row the same width and fills the left with spaces until the reverse suffix begins — so A, BA, CBA, … line up on the right edge.
In C you solve it with nested char loops: outer i grows the peak, inner j scans top..A, and j > i decides space vs letter.
It combines three beginner skills: fixed-width scans, leading-space padding, and descending letter order — the same toolkit used for many right-aligned pyramids.
Every row scans top..A columns.
j > i pads until the suffix starts.
Descending j prints BA, CBA, DCBA…
Outer i from A to top lengthens the suffix.
In short: for each peak i, scan top..A — print a space while j > i, otherwise print j, then call printf("\n").
Given a top letter (like E), print a right-aligned pyramid of reverse alphabet suffixes.
// Classic sample (top = E; leading spaces matter)
// A
// BA
// CBA
// DCBA
// EDCBA | Item | Type | Description |
|---|---|---|
top | char | Highest letter (e.g. E). Line width = top − ‘A’ + 1. |
| Printed output | text | Right-aligned reverse suffixes with leading spaces. |
for i from 'A' to top:
for j from top down to 'A':
if j > i: print space
else: print j
print newline | Approach | Idea | Best for |
|---|---|---|
| Fixed-width scan | Space-or-letter in each column | Matching this classic sample |
| Explicit pad + suffix | Print spaces, then i..A reverse | Clearer reading / teaching rewrite |
| Goal | Pattern |
|---|---|
| Row peaks | for (char i = 'A'; i <= top; i++) |
| Fixed scan | for (char j = top; j >= 'A'; j--) |
| Pad vs letter | if (j > i) printf(" "); else printf("%c", j); |
| End the row | printf("\n"); |
| Left-aligned reverse | See Program 2 |
| Add right mirror | See Program 19 |
Same fixed-width row — different roles on each column.
j > iLeading pads that create right alignment
j <= iReverse suffix letters for the current peak
E..AInner direction makes BA, CBA, DCBA…
breakEnds the row after the full width scan
Reach for this when teaching right alignment with reverse letter fills.
Keep one half of the dual scan — the pad-and-suffix idea alone.
Practice leading spaces on a fixed-width console line.
Same reverse letters; left-aligned vs right-aligned layout.
Padding intuition helps when you later center rows.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one condition (j > i) turns a flat reverse scan into a right-aligned pyramid.
Enter a top letter from A to J and draw the right-aligned reverse pyramid in the browser.
Three complete C programs — fixed top E, scanf top letter, and explicit pad + suffix. . Click View Output to reveal sample console results.
Print five right-aligned reverse rows with a fixed-width scan.
EOuter i is the row peak. Inner j sweeps E down to A and prints a space until it reaches i.
#include <stdio.h>
int main() {
int i, j;
for (i = 'A'; i <= 'E'; ++i) {
for (j = 'E'; j >= 'A'; --j) {
if (j > i) {
printf(" ");
} else {
printf("%c", j);
}
}
printf("\n");
}
return 0;
} When i = 'C', columns E and D print spaces; then C, B, A print → ··CBA. When i = 'E', every column is a letter → EDCBA.
Let the user choose the last letter.
The pattern keeps the line width fixed to the chosen top letter. Check scanf’s return value and require A–Z in real apps.
#include <stdio.h>
int main() {
char top;
int i, j;
printf("Enter the top letter (like E): ");
scanf(" %c", &top);
for (i = 'A'; i <= top; ++i) {
for (j = top; j >= 'A'; --j) {
if (j > i) {
printf(" ");
} else {
printf("%c", j);
}
}
printf("\n");
}
return 0;
} Same j > i rule; only the shared bounds follow top. With top = 'D' you get a 4-column right-aligned pyramid.
Same shape with separate pad and suffix loops.
Often clearer to read: print leading spaces first, then letters from the peak down to A.
#include <stdio.h>
int main() {
char top = 'E';
int width = top - 'A' + 1;
char i, ch;
int s, letters, pad;
for (i = 'A'; i <= top; ++i) {
letters = i - 'A' + 1;
pad = width - letters;
for (s = 0; s < pad; ++s) {
printf(" ");
}
for (ch = i; ch >= 'A'; --ch) {
printf("%c", ch);
}
printf("\n");
}
return 0;
} Peak i needs i - 'A' + 1 letters and width - letters leading spaces. The suffix loop prints i down to A — same visual pyramid as the scan version.
i moves from A to top, increasing the visible suffix each time.
j runs from top down to A, giving a fixed-width line.
If j > i print a space; otherwise print j. Leading spaces push the suffix to the right edge.
printf("\n") ends the row so the next peak starts fresh.
For n letters, total work is O(n²) time, O(1) extra memory.
ETrace each peak i and how many pads vs letters print.
i | Leading spaces | Suffix | Printed row |
|---|---|---|---|
A | 4 | A | ····A |
B | 3 | BA | ···BA |
C | 2 | CBA | ··CBA |
D | 1 | DCBA | ·DCBA |
E | 0 | EDCBA | EDCBA |
Pad count is top - i (as char distance). Each row still scans 5 columns.
Where this right-aligned reverse pyramid shows up beyond the homework prompt.
Clearest alphabet demo of leading spaces on a fixed width.
Example: print . instead of spaces while debugging.
Same reverse letters — left-aligned vs right-aligned.
Example: print both for top E side by side.
This scan is the left half of the mirrored-gap pattern.
Example: add a right mirror pass next.
Teach pad count separately from the reverse suffix (Example 3).
Example: compare scan vs pad+suffix outputs.
Fixed-width scans make O(n²) easy to count.
Example: 5 rows × 5 columns = 25 writes.
Practice reading and validating a single top letter.
Example: reject empty strings and non A–Z input.
Pro Tip: say “pad while above the peak, then print reverse letters” before coding — that story prevents flipped alignment.
Why this pattern earns a spot after left-aligned reverse triangles.
Missing pads or a flipped inner loop show up as a broken pyramid immediately.
Fixed-width scan or explicit pad/suffix loops teach the same shape.
Master one half before adding the mirrored right ramp.
Streaming output needs no storage beyond loop variables.
Pro Tip: learn the classic scan version first; treat the explicit pad/suffix rewrite as a clarity upgrade afterward.
Small habits that keep right-aligned reverse pyramids clean.
Always scan top..A so shorter suffixes stay right-aligned.
Tabs change width by editor settings and ruin alignment.
Require a single A–Z character; empty scanf breaks scanf.
Temporarily print . instead of spaces to count the pads.
Trace two spaces then CBA on paper before coding larger tops.
Pro Tip: if letters sit on the left with trailing spaces, you almost certainly flipped the j > i condition.
Mistakes that commonly break right-aligned reverse alphabet pyramids.
Using j < i for spaces left-aligns or garbles the suffix.
→ Print a space when j > i.
Going A..top prints forward letters (AB, ABC) instead of reverse suffixes.
→ Keep j descending from top to A.
Alignment depends on the editor’s tab size.
→ Always print a single space character.
scanfEmpty or non-letter input leaves top invalid.
→ Check scanf’s return value and require A–Z.
printf("\n") Mid-ScanBreaks the row into one character per line.
→ Call printf("\n") only after the full width finishes.
Check these inputs before calling the solution done.
Output is just A (no pads).
Five rows ending in EDCBA.
Four columns; last row DCBA.
Reject or cap so letters stay in A–Z.
Unchecked scanf fails silently — check the return value.
Same loops; only the pad character changes.
Try these variations to lock in the pattern.
j > i creates leading spaces; descending j creates reverse suffixes.Quick Takeaway: scan top..A, pad while above the peak, print the reverse suffix, then break the line — that is the whole pyramid.
| Program | Time | Extra space |
|---|---|---|
| Fixed-width scan (Examples 1–2) | O(n²) | O(1) |
| Explicit pad + suffix (Example 3) | O(n²) | O(1) |
With n = top − ‘A’ + 1, each of n rows scans n columns (or pads + letters totaling n), so work is O(n²).
The right-aligned reverse alphabet pyramid is a small nested-loop exercise with lasting payoff: fixed-width scans, leading-space padding, and descending letter fills. Master the classic ····A…EDCBA sample, then try user input and the explicit pad rewrite.
Practice the three examples above, then continue to Program 21’s diamond alphabet pattern with alternating stars.
Scan top..A, print spaces while j > i, print letters otherwise, and break only after the scan.
j > ij > i unless you want left alignmentprintf("\n") inside the column scanscanfPrint the right-aligned reverse alphabet pyramid the beginner-friendly way.
Pad + reverse suffix
DefinitionAlways top..A
Codej > i → space
CodeEnds each scan
I/OO(n²) time
AnalysisEach line has fixed width (five columns for A…E). Scanning j from E down to A, letters higher than the row peak i turn into spaces, so the visible suffix (CBA, DCBA, …) sits on the right.
Next up: diamond patterns that mix letters and stars.
12 people found this page helpful