Right-Aligned Reverse Alphabet Pyramid in C

Beginner
⏱️ 8 min read
📚 Updated: Aug 2026
🎯 3 Code Examples
🚀 Live Preview
Nested Loops

What You’ll Learn

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.

Shape Rule

Reverse slices

Rows grow: E, then E D, … E D C B A.

Two Loops

Pad, then letters

Empty cells first; reverse slice second.

Fixed Cells

Width 2

Pad with " "; print letters with %2c.

Char Outer

E → A

Outer i descends from the top letter to A.

Live Preview

Top letter

Pick a top letter (A–F in the preview) and draw.

O(n²)

Complexity

n rows × O(n) pad + letter work.

Introduction

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.

Why it matters?

It shows how reverse ranges, padding counts, and format widths work together — a step beyond continuous k++ streams.

Key Highlights

Reverse Slice

Each row prints top..i.

Right Align

Pads shrink as rows grow.

Width 2

" " matches %2c.

vs Program 22

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").

📝 Problem & Approach

Given a top letter (or fixed E), print a right-aligned pyramid of reverse alphabet slices ending at A.

c
// Five rows (monospace; each cell is width 2)
//         E
//       E D
//     E D C
//   E D C B
// E D C B A

Inputs & Outputs

ItemTypeDescription
topcharHighest letter (e.g. E). Rows run from top down to A.
Printed outputtextRight-aligned reverse slices in fixed-width cells.

Minimal workflow

Pseudocode
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 comparison

ApproachIdeaBest for
Char loops (classic)Pad A..(i-1); letters top..iMatching this sample
Int row indexn = top-'A'+1; pad n-row; letters by indexWhen you prefer int counters

⚡ Quick Reference

GoalPattern
Outer rowsfor (char i = top; i >= 'A'; i--)
Pad cellsfor (char j = 'A'; j < i; j++) printf(" ");
Letter slicefor (char j = top; j >= i; j--) printf("%2c", j);
End rowprintf("\n");
Sequential streamSee Program 22 (k++)

📋 Pad vs Letters vs Newline

Same row — three roles that build the reverse pyramid.

printf(" ")
pad

2-column empty cells for right alignment

printf("%2c", j)
slice

Reverse letters from top down to row letter

i descends
grow

Each row adds one more letter on the left of the slice

printf("\n")
break

Ends the row after pads + letters

Context

When This Pattern Shows Up

Reach for this when teaching reverse ranges with fixed-width alignment.

  1. After Program 22

    Same grid idea; reverse slices instead of a continuous stream.

  2. Char-loop drills

    Practice looping on char instead of only int.

  3. Compare with Program 20

    Similar reverse right-align idea; this page stresses width-2 cells.

  4. Format-width labs

    Match pad string length to %2c exactly.

  5. Not a UI layout tool

    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.

🔮 Live Preview

Choose a top letter from A to F and draw the right-aligned reverse pyramid in the browser (monospace cells).

Try E (classic sample) or C (three rows). Preview allows A–F.

Live result
Press "Draw pattern".

Examples Gallery

Three complete C programs — fixed A–E, scanf top letter, and an int-index style. Click View Output to reveal sample console results.

📚 Getting Started

Print five right-aligned reverse rows from E down to A.

Example 1 — Fixed A–E

First print padding pairs, then print letters from E down to the current row letter.

c
#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;
}

How It Works

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.

📈 Practical Variant

Let the user choose the starting (top) letter.

Example 2 — Top Letter Input

The pattern prints rows from the chosen top letter down to A. Check scanf’s return value and require A–Z in real apps.

c
#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;
}

How It Works

Same pad/letter rules; only the shared top letter changes. Both the outer start and the letter-loop start use top.

⚡ Int Style

Same shape with integer row and column indexes.

Example 3 — Int Row Index

Often clearer if you think in row numbers: pad n - row cells, then print row letters from the top down.

c
#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;
}

How It Works

Row 1 prints one letter (E); row 5 prints five (E..A). Pad count is n - row; letter k is (char)(top - k).

🧠 How the Algorithm Prints Rows

1

Outer loop descends from E to A

Top row has one letter (E); each next row grows by one letter until E D C B A.

Descend
2

Padding loop shifts the block

For j = A..(i-1) we print " ". When i is E we print 4 padding cells; when i is A, we print 0.

Pad
3

Letter loop prints a reverse slice

Second inner loop prints j = E..i, using %2c to keep each letter 2 columns wide.

Slice
4

New line

printf("\n") ends the row so the next lower i can grow the slice.

Break
=

Right-aligned growth

Two inner loops keep the block aligned while it grows by one letter per row — O(n²) time.

🔎 Worked Walkthrough — Top = E

Trace each row’s pads, reverse slice, and printed line.

iPad cellsLettersPrinted row
E4E········E
D3E D······E D
C2E D C····E D C
B1E D C B··E D C B
A0E D C B AE D C B A

Row count = top - 'A' + 1 (5 for E). Each cell is 2 columns wide.

Use Cases

Where this reverse right-aligned pyramid shows up beyond the homework prompt.

1. Reverse Range Labs

Clearest demo of printing top..i each row.

Example: swap descending for ascending and compare.

2. Pair with Program 22

Same fixed-width grid — stream vs reverse slice.

Example: print both for 5 rows side by side.

3. Char Loop Practice

Outer and inner loops over char ranges.

Example: rewrite with int indexes (Example 3).

4. Format Width Practice

Match pad string length to letter field width.

Example: try one-space pads and watch columns break.

5. Complexity Intuition

Growing reverse slices make O(n²) easy to see.

Example: 5 rows print 1+2+3+4+5 letter cells.

6. Bridge to Program 24

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.

Advantages

Why this pattern earns a spot after sequential right-aligned triangles.

  1. 1. Instant Visual Feedback

    Wrong pad count or letter direction shows up immediately.

  2. 2. Two Clear Rewrites

    Char loops or int indexes teach the same shape.

  3. 3. Reverse Range Practice

    A natural place to learn descending char loops.

  4. 4. O(1) Extra Memory

    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.

Usage Tips

Small habits that keep reverse right-aligned pyramids clean.

  1. 1. Match Pad Width to Letters

    Use two spaces when letters use %2c.

  2. 2. Keep Letter Loop Starting at Top

    Always begin the slice at the top letter, not at i.

  3. 3. Validate Top Letter Input

    Require a single A–Z character; normalize case if needed.

  4. 4. Use a Monospace Font

    Proportional fonts make width-2 cells look misaligned.

  5. 5. Compare with Program 22

    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.

Common Pitfalls

Mistakes that commonly break reverse right-aligned pyramids.

  1. 1. Starting Letters at i

    Rows become single letters or wrong slices.

    → Letter loop must start at top (or E), not at i.

  2. 2. One-Space Padding

    Empty cells become narrower than %2c letter fields.

    → Print " " (two spaces) for each pad cell.

  3. 3. Proportional Font Preview

    Columns look broken even when the code is correct.

    → View output in a monospace terminal/font.

  4. 4. Unchecked scanf

    Empty or non-letter input leaves top invalid.

    → Check scanf’s return value and require A–Z.

  5. 5. Confusing with Program 22

    Using k++ produces A, B C, D E F… instead of reverse slices.

    → Print j from top down to i each row.

Edge Cases

Check these inputs before calling the solution done.

top = A

Single letter

Output is just A (no pads).

top = E

Classic sample

Five rows through E D C B A.

top = C

Smaller pyramid

Three rows (Example 2).

Lowercase

Case mismatch

Normalize with char.toupper if needed.

Bad input

Empty / multi-char

Unchecked scanf fails silently — check the return value.

top < A

Invalid range

Reject non A–Z tops so loops do not misbehave.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Swap for sequential

  • Rebuild Program 22’s stream on the same grid
  • See Program 22

2. Ascending slices

  • Print i..top instead of top..i
  • Compare the visual change

3. Int-index version

  • Use row numbers (Example 3)
  • Confirm output matches the char loops

4. Continue to Program 24

Notes

  • Reverse slice. Each row reprints from the top letter down to the current row letter.
  • Pad width must match letter field width (" "%2c).
  • Row count is top - 'A' + 1 (5 for E).
  • Unlike Program 22, there is no running 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.

⏱️ Time and Space Complexity

ProgramTimeExtra 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²).

Wrap Up

🎉 Conclusion

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.

💡 Best Practices

✅ Do

  • Start both outer and letter loops from the top letter
  • Match pad width to letter field width
  • View output in a monospace font
  • Check scanf and require an A–Z top letter
  • State O(n²) when asked about complexity

❌ Don’t

  • Start the letter loop at i instead of top
  • Pad with a single space when letters use width 2
  • Assume proportional fonts will align columns
  • Confuse this with Program 22’s k++ stream
  • Call printf("\n") inside the pad or letter loop

Key Takeaways

Knowledge Unlocked

Five things to remember about this alphabet pattern

Print the right-aligned reverse alphabet pyramid the beginner-friendly way.

5
Core concepts
02

Letters

top..i each row

Code
2 03

Width

" " & %2c

Code
04

New line

Ends each row

I/O
O 05

Complexity

O(n²) time

Analysis

❓ Frequently Asked Questions

The first prints padding so the visible letters are right-aligned. The second prints letters from E (or your top letter) down to the current row letter i.
Each letter is printed in a width-2 field with printf("%2c", j), so two spaces keep empty cells the same width and the pyramid aligned in monospace output.
Program 22 uses one running counter k++ across all rows (A..O). Program 23 prints a reverse slice each row using the loop variable j (E..i).
printf("%2c", j) (or two spaces) stays on the same line for pads and letters. printf("\n") ends the row after both inner loops finish.
Yes. Change the second loop to always begin from your chosen top letter and decrement to the row letter — Example 2 does this with user input.
O(n²) for n rows because each row does O(n) work across the padding + letter loops.
Use scanf(" %c", &top), require A–Z, and reject non-letters.
For top = E, when i is E you print 4 pad cells (A..D); when i is A you print 0. Pads = (i − A).

Did you Know? 🔊

Outer 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.

Continue to Alphabet Pattern 24

Next up: palindromic alphabet pyramids.

Program 24 tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful