Reverse Centered Alphabet Pyramid in C

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

What You’ll Learn

Build a full reverse-centered alphabet diamond by reusing Program 28’s row rule twice: descend the floor from E to A, then ascend from B to E so the center row is not repeated. Compare Program 21 (diamond symmetry) and Program 24 (palindrome triangles). Includes a live preview, worked C examples, edge cases, and complexity.

Two Phases

Upper + lower

E..A down, then B..E up — one center.

Same Row Rule

From Prog 28

Left E..A, right B..E, floor j > i.

Skip Center

Start at B

Lower half begins at i = 1 to avoid a double A row.

2n−1 Rows

Closed diamond

For A..E, nine rows of width 9.

Live Preview

Top letter

Pick a top letter (A–F) and draw the full pyramid.

O(n²)

Complexity

O(n) rows × O(n) cells each.

Introduction

A reverse centered alphabet pyramid keeps every row full width while the floor letter moves from the peak down to A at the center, then back up to the peak — a closed diamond of layered letters.

In C you reuse the same mirrored scans and j > i floor rule as Program 28, then add a second outer loop that ascends from B so the center line appears once.

Why it matters?

It teaches two-phase outer loops, skipping a duplicated center, and composing a full shape from a reusable row printer — skills that transfer to diamonds and concentric grids.

Key Highlights

Upper

Floor E → A.

Lower

Floor B → E.

j > i

Shared cell rule.

One A row

Lower starts at B.

In short: for each floor i in k..A then B..k, scan left k..A and right B..k, printing j > i ? j : i, then call printf("\n").

📝 Problem & Approach

Given a top letter (or fixed E), print a reverse-centered alphabet pyramid: Program 28’s layered square, then the matching bands back up without repeating the center.

c
// Nine rows (space after each letter; width 9)
// 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   <-- center (once)
// 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 E

Inputs & Outputs

ItemTypeDescription
top / kchar / intTop letter; k = top - 'A' (4 for E). Rows = 2k+1.
Printed outputtextFull reverse-centered pyramid of width 2k+1.

Minimal workflow

Pseudocode
k = top - 'A'
printRows(i from k down to 0)   // upper incl. center
printRows(i from 1 up to k)     // lower, skip A

printRows(i):
    for j from k down to 0:      // left half
        print (j > i ? letter[j] : letter[i]) + " "
    for j from 1 to k:           // right half
        print (j > i ? letter[j] : letter[i]) + " "
    print newline

Approach comparison

ApproachIdeaBest for
Two-phase outer loopsUpper k..A + lower B..k with shared row printerMatching this classic sample
Single abs-distance loopMap row to floor via distance from centerOne outer loop; same visuals

⚡ Quick Reference

GoalPattern
Top letterchar k = 'E'; (or from scanf)
Upper halffor (i = k; i >= 'A'; --i) print_row(...);
Lower halffor (i = 'B'; i <= k; ++i) print_row(...);
Left / rightj = k..A then j = B..k with j > i ? j : i
Upper onlySee Program 28

📋 Upper vs Lower vs Row Rule

Four roles that close the reverse-centered pyramid.

i = k..A
upper

Descends to the A-center row

i = B..k
lower

Ascends back; skips duplicating A

j > i ? j : i
floor

Same cell rule as Program 28

printf("\n")
break

Ends each full-width row

Context

When This Pattern Shows Up

Reach for this when closing Program 28’s square into a full reverse-centered diamond.

  1. After Program 28

    Reuse the same row printer; add the lower phase.

  2. Two-phase loop drills

    Practice descending then ascending without a double center.

  3. Helper extraction

    Factor print_row once and call it from both phases.

  4. Index practice

    Map letters to array indexes and scale with k.

  5. Not a UI layout tool

    This is a console teaching pattern — not how you build modern app screens.

Key benefit: one shared row rule plus a lower half that starts at B is the cleanest way to close Program 28 into a full reverse-centered pyramid.

🔮 Live Preview

Choose a top letter from A to F and draw the reverse centered alphabet pyramid in the browser.

Try E (classic sample) or C (smaller pyramid). Preview allows A–F.

Live result
Press "Draw pattern".

Examples Gallery

Three complete C programs — fixed A–E, scanf top letter, and shared print_row helpers. Click View Output to reveal sample console results.

📚 Getting Started

Print nine reverse-centered rows from E down to A and back up to E.

Example 1 — Fixed A–E

Same row logic as Program 28, printed in two phases to complete the reverse centered pyramid.

c
#include <stdio.h>

int main() {
    char k = 'E';
    char i, j;

    /* Upper half (E down to A) */
    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");
    }

    /* Lower half (B up to E) — skip repeating the A row */
    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

The upper loop mirrors Program 28 through the A-center row. The lower loop starts at i = 'B' so that center line is not printed twice.

📈 Practical Variant

Let the user pick the top letter (like E).

Example 2 — Top Letter Input

Works for A..top with the same two-phase pyramid. Check scanf’s return value and require A–Z in real apps.

c
#include <stdio.h>

int main() {
    char top, k, i, j;

    printf("Enter top letter (like E): ");
    scanf(" %c", &top);
    k = top;

    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

k = top scales both phases and both halves. For top = C you get 5 rows of width 5 (2*(top-'A')+1).

⚡ Helper Style

Same shape with shared print_cell and print_row helpers.

Example 3 — Helper Functions

Often clearer: one function owns the floor rule; another prints a full row so both phases stay thin.

c
#include <stdio.h>

void print_cell(char j, char i) {
    if (j > i) {
        printf("%c ", j);
    } else {
        printf("%c ", i);
    }
}

void print_row(char k, char i) {
    char j;

    for (j = k; j >= 'A'; --j) {
        print_cell(j, i);
    }
    for (j = 'B'; j <= k; ++j) {
        print_cell(j, i);
    }
    printf("\n");
}

int main() {
    char k = 'E';
    char i;

    for (i = k; i >= 'A'; --i) {
        print_row(k, i);
    }
    for (i = 'B'; i <= k; ++i) {
        print_row(k, i);
    }

    return 0;
}

How It Works

print_cell owns the j > i rule; print_row owns both halves. The two outer loops only decide which floors to visit.

🧠 How the Algorithm Prints Rows

1

Reuse the Program 28 row rule

Each row prints a left scan (E..A) and a right scan (B..E). Each cell prints j when j > i, otherwise prints i.

Logic
2

Upper half: i goes down

Run i = k..'A' (E to A) to reach the center row with A — this is Program 28.

Upper
3

Lower half: i goes up (skip center)

Start the second loop at B (i = 1) to avoid printing the center line twice.

Lower
4

Keep the row width constant

Left half has k+1 letters and right half has k letters, so total width is 2k+1. Every row stays aligned.

Width
=

Upper + lower = closed pyramid

Print down to the center (A row), then the matching bands back up — O(n²) time for n letters.

🔎 Worked Walkthrough — Top = E (k = 4)

Trace each floor and the resulting 9-letter line across both phases.

PhaseiFloorPrinted row
Upper4EE E E E E E E E E
Upper3DE D D D D D D D E
Upper2CE D C C C C C D E
Upper1BE D C B B B C D E
Upper0AE D C B A B C D E
Lower1BE D C B B B C D E
Lower2CE D C C C C C D E
Lower3DE D D D D D D D E
Lower4EE E E E E E E E E

Width is always 2×4+1 = 9. Total rows are 2×5−1 = 9. The A-center row appears only once (upper phase).

Use Cases

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

1. Composition Labs

Clearest demo of building a full shape from a reusable row.

Example: start lower at 0 and watch a double A row.

2. Symmetry Practice

Upper and lower floors mirror around the center.

Example: compare row i=2 upper with i=2 lower.

3. Index Mapping

Practice k = top - 'A' with an alphabet array.

Example: scale from E to H without rewriting loops.

4. Helper Extraction

Factor print_cell + print_row (Example 3).

Example: call print_row from both phases only.

5. Complexity Intuition

2n−1 rows × width 2n−1 makes O(n²) easy to see.

Example: 9 rows × 9 cells = 81 prints for A..E.

6. Bridge from Program 28

Upper half is Program 28; lower half closes the diamond.

Example: revisit Program 28.

Pro Tip: say “print Program 28, then floors B..E with the same row” before coding — that story prevents a duplicated center A.

Advantages

Why this pattern earns a spot right after the symmetric decreasing square.

  1. 1. Instant Visual Feedback

    A double center or broken mirror shows up immediately.

  2. 2. Reuses Program 28

    No new cell rule — only a second outer phase.

  3. 3. Scales Cleanly

    Change k and the whole diamond grows.

  4. 4. Helper-Friendly

    print_row keeps both phases short and readable.

Pro Tip: master Program 28 first; this page is mostly “call that row again while climbing from B.”

Usage Tips

Small habits that keep reverse-centered pyramids clean.

  1. 1. Start the Lower Half at 1

    Starting at 0 duplicates the A-center row.

  2. 2. Keep One Floor Rule

    Reuse j > i ? j : i on both halves of every row.

  3. 3. Set k from the Top Letter

    Use k = top - 'A' so scaling stays automatic.

  4. 4. Validate Top Letter Input

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

  5. 5. Extract print_row When Ready

    Duplicated left/right loops across two phases are a strong helper signal.

Pro Tip: if two identical A-center rows appear, the lower half almost certainly started at i = 0.

Common Pitfalls

Mistakes that commonly break reverse-centered alphabet pyramids.

  1. 1. Starting the Lower Half at 0

    Duplicates the A-center row.

    → Start the lower phase at i = 1.

  2. 2. Starting the Right Half at 0

    Duplicates the center A inside a row.

    → Start the right scan at j = 1.

  3. 3. Wrong Floor Condition

    Using j >= i or swapping operands changes layer borders.

    → Keep j > i ? j : i.

  4. 4. Unchecked scanf

    Empty or non-letter input leaves top invalid.

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

  5. 5. Forgetting the Lower Phase

    Stopping after the first loop leaves only Program 28’s square.

    → Add for (i = 1; i <= k; i++) with the same row printer.

Edge Cases

Check these inputs before calling the solution done.

top = A

Single letter

Output is just A (lower half empty).

top = E

Classic sample

9 rows × width 9 through the A center.

top = C

Smaller pyramid

5 rows × width 5 (Example 2).

Lowercase

Case mismatch

Normalize with char.toupper if needed.

Bad input

Empty / multi-char

Unchecked scanf fails silently — check the return value.

Numbers

Same structure

Replace alpha with 5..1 style indexes in both phases.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Duplicate the center on purpose

  • Start the lower half at 0 once
  • Confirm why the sample starts at 1

2. Extract print_row

  • Use helpers (Example 3)
  • Call print_row from both phases

3. Scale to H

  • Set top = H and recompute k
  • Check rows = width = 2k+1

4. Compare with Program 28

  • Confirm upper half matches Program 28
  • See Program 28

Notes

  • Two phases. Upper E..A then lower B..E keep a single center row.
  • The floor rule j > i ? j : i is identical to Program 28.
  • Row width and row count are both 2k + 1 (9 for A..E).
  • Program 30 switches to decreasing/increasing alphabet rows of fixed width.

Quick Takeaway: print Program 28’s rows down to A, then the same rows from B up to E, with one shared j > i rule.

⏱️ Time and Space Complexity

ProgramTimeExtra space
Inline / input (Examples 1–2)O(n²)O(1) (plus alphabet source)
Helper functions (Example 3)O(n²)O(1)

For n letters there are 2n−1 rows and each row prints O(n) cells (width 2n−1), so total work is O(n²).

Wrap Up

🎉 Conclusion

The reverse centered alphabet pyramid is Program 28 closed into a diamond: the same mirrored row rule, plus a lower phase that starts at B so the A-center appears once. Master the classic E…A…E sample, then try user input and the helper rewrite.

Practice the three examples above, then continue to Program 30’s decreasing and increasing alphabet rows.

Upper k..A, lower B..k, same left/right scans with j > i, then break each line.

💡 Best Practices

✅ Do

  • Start the lower half at i = 1
  • Start the right half at j = 1
  • Reuse one j > i floor rule on both halves
  • Derive k from the top letter
  • State O(n²) when asked about complexity

❌ Don’t

  • Start the lower half at 0 (duplicates the A row)
  • Hard-code k without updating the alphabet source
  • Change the floor rule between phases
  • Skip validating top-letter input
  • Call printf("\n") inside either half loop

Key Takeaways

Knowledge Unlocked

Five things to remember about this alphabet pattern

Print the reverse centered alphabet pyramid the beginner-friendly way.

5
Core concepts
> 02

Choice

j > i ? j : i

Code
1 03

Lower

Start at B

Code
04

Rows

2n−1 total

Shape
O 05

Complexity

O(n²) time

Analysis

❓ Frequently Asked Questions

The first loop decreases i from E down to A, printing each layered row toward the center. The second increases i from B back to E with the same row rule so the pyramid widens again without repeating the A-centered row.
Because the A-centered row already appears in the upper half. Starting from B prevents duplicating the center line.
If n is the number of letters from A to the top letter, total rows are 2n−1 (9 rows for A..E).
It prints the border letter when the column letter j is above the current row floor i; otherwise it prints the floor letter. The same rule applies on both left and right halves of every row.
The left scan goes E down to A; the right scan goes B up to E so the middle A appears once and the row mirrors.
O(n²) because there are O(n) rows and each row prints O(n) cells.
Use scanf(" %c", &top), require A–Z, and reject non-letters.
Program 28 is exactly the upper half of this pyramid. Program 29 reuses that row logic, then mirrors upward from B to E for the closed diamond.

Did you Know? 🔊

Reuse Program 28’s row logic twice: first with i from E down to A, then with i from B up to E so the center row is not duplicated. Each row stays full width (2n-1 cells); total rows are also 2n-1 for n letters.

Continue to Alphabet Pattern 30

Next up: decreasing and increasing alphabet row patterns.

Program 30 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