C Reverse Alphabet Pyramid Pattern (Centered)

Beginner
8 min read
Updated: Sep 2026
3 programs
Live preview

What Is This Pattern?

A reverse centered alphabet pyramid is a diamond of letter layers: it shrinks from a full top row of Es down to the center E D C B A B C D E, then widens again back to all Es.

Remember
Rule: print Program 28’s row for i = top..A,
      then again for i = B..top (skip center twice)

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
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     ← top = 'E'

Each row still uses the same cell rule as Program 28: print j when j > i, otherwise print the floor i. The new idea is the second outer loop that mirrors upward from B.

How to Solve It

Reuse one row printer twice — once descending to A, once ascending from B — so the center line appears only once.

MethodIdeaBest for
Two outer phasesUpper k..A, lower B..k; same row scansLearning, interviews, exams
Helpers print_rowOne function owns both halves; call it from both loopsCleaner demos once the phases click

Pseudocode

Pseudocode
k = topLetter

function print_row(i):
    for j from k down to 'A':
        print (j > i ? j : i) and a space
    for j from 'B' to k:
        print (j > i ? j : i) and a space
    print newline

for i from k down to 'A':
    print_row(i)
for i from 'B' to k:
    print_row(i)

Cheat sheet

GoalPattern
Upper halffor (i = k; i >= 'A'; i--)
Lower halffor (i = 'B'; i <= k; i++)
Left halffor (j = k; j >= 'A'; j--)
Right halffor (j = 'B'; j <= k; j++)
Cell ruleprintf("%c ", j > i ? j : i);
End the rowprintf("\n");
Total rows2 * (k - 'A') + 1 (= 2n - 1)

Printing Letters vs Starting a New Line

APIEffectUse for
printf("%c ", ch)Letter + space; stays on the lineEach cell
printf("\n")Ends the current lineAfter both halves of a row

Live Preview

Change the letter count (top = A + n - 1) and the diamond updates instantly — capped at 8 for readability.

Whole numbers from 1 to 8. With n = 5, top is E and you get the classic sample.

Live result 9 rows · 81 cells
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 E

Worked Walkthrough — top = 'C'

Smaller board (n = 3, width 5, total rows 5) so both phases are easy to check by hand.

PhaseFloor iPrinted row
Upper'C'C C C C C
Upper'B'C B B B C
Upper'A'C B A B C
Lower'B'C B B B C
Lower'C'C C C C C

The lower half starts at 'B', so the center C B A B C row is not printed twice.

C Programs

Three complete programs: fixed top letter, scanf input, and a helper rewrite. Use View Output to reveal sample results.

Example 1 — Fixed top at 'E'

Hard-coded top — Program 28’s row twice: down to A, then up from B.

C
#include <stdio.h>

int main(void)
{
    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 A) */
    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

1. Upper phase lowers the floor. i runs from 'E' down to 'A' — same rows as Program 28.

2. Each row mirrors left and right. Left scans k..A; right scans B..k; cells print j > i ? j : i.

3. Lower phase starts at B. Starting at 'B' skips a second center row and widens back to the top letter.

4. Break the line once per row. printf("\n") after both halves — never inside a half loop.

Example 2 — User Input Version

Read the top letter at runtime with scanf. Prefer a leading space in the format and validate A–Z.

C
#include <stdio.h>

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

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

    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

1. Prompt and read. scanf(" %c", &k) — the leading space skips leftover newlines.

2. Same diamond core. Only the top letter changes; both phases and the cell rule stay identical.

3. Safer input tip. Reject lowercase or non-letters:

Safer input
if (scanf(" %c", &k) != 1 || k < 'A' || k > 'Z')
{
    printf("Enter an uppercase letter A–Z.\n");
    return 1;
}

Example 3 — Helper functions

Same shape with print_cell and print_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(void)
{
    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

1. Centralize the cell rule. print_cell encodes j > i ? j : i once.

2. Centralize the row. print_row owns both halves and the newline.

3. Phases stay obvious. main only shows “down to A, then up from B” — the important new idea.

Edge Cases & Pitfalls

Check these before calling the solution done.

Lower from A

Duplicated center

Starting the lower half at 'A' prints the center row twice. Always start at 'B'.

Right from A

Fat middle

Starting the right half at 'A' prints A twice in every row. Start at 'B'.

Wrong compare

Broken borders

Use j > i (strict). j >= i shifts floor vs border cells.

\n early

Broken rows

Call printf("\n") only after both halves finish.

top = 'A'

Single A

One row with a single A — the lower loop never enters.

scanf

Leading space in format

Use scanf(" %c", &k) so a leftover newline is not read as the letter.

Time and Space Complexity

ProgramTimeExtra space
Inline phases (Examples 1–2)O(n²)O(1)
Helpers (Example 3)O(n²)O(1)

For n letters there are 2n - 1 rows and each row prints 2n - 1 cells — still quadratic in n.

Key Takeaways

  • Reuse Program 28’s row: print j > i ? j : i on mirrored left/right scans.
  • Two phases: upper k..A, then lower B..k so the center is not duplicated.
  • Break the row: call printf("\n") only after both halves.
  • Complexity: O(n²) time; O(1) extra space.

One line: for each floor i in k..A then B..k, print the Program 28 row and printf("\n").

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.
printf("%c ", ch) prints a letter plus a trailing space and stays on the same line. printf("\n") ends the current line after both halves.
O(n²) because there are O(n) rows and each row prints O(n) cells.
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.

Next: Decreasing & Increasing Rows

Print alphabet rows that shrink then grow again.

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