C Symmetric Alphabet Pyramid Pattern

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

What Is This Pattern?

A symmetric alphabet pyramid prints centered palindromic rows: each line climbs from A to a peak letter, then mirrors back down to A without repeating the peak.

Remember
Rule: spaces + A..i + (i−1)..A

    A
   ABA
  ABCBA
 ABCDCBA
ABCDEDCBA     ← top = 'E'

Three stages per row: leading spaces for centering, ascending A..i, then descending (i − 1)..A. Compare with Program 24 (similar palindromes) and Program 31 (hollow V).

How to Solve It

Two ways to emit the same pyramid — a classic bridge variable (--n), or an explicit descending loop.

MethodIdeaBest for
Bridge variableAfter A..i, set n = k - 1 and print alpha[--n]Matching classic textbook / exam style
Explicit mirrorLoop p from i - 1 down to 0Clearer demos once the skip-center rule clicks

Pseudocode

Pseudocode
end = top - 'A'
for i from 0 to end:
    print (end - i) spaces
    for k from 0 to i:     print alpha[k]   // A..i
    for p from i-1 to 0:   print alpha[p]   // (i-1)..A
    print newline

Cheat sheet

GoalPattern
Top indexint end = top - 'A'; (4 for E)
Rowsfor (i = 0; i <= end; i++)
Leading spacesfor (j = end; j > i; j--) printf(" ");
Ascending halffor (k = 0; k <= i; k++) printf("%c", alpha[k]);
Bridge mirrorn = k - 1; for (m = 0; m < i; m++) printf("%c", alpha[--n]);
Explicit mirrorfor (p = i - 1; p >= 0; p--) printf("%c", alpha[p]);
Letters on row i2i + 1 (peak printed once)

Printing Letters vs Starting a New Line

APIEffectUse for
printf(" ") / printf("%c", ...)Stays on the same lineEach space and letter
printf("\n")Ends the current lineAfter spaces + ascending + mirror finish a row
putchar(ch)Same as printing one characterOptional leaner style once loops click

Live Preview

Change the top letter and the centered palindrome pyramid updates instantly — row i has 2i + 1 letters.

One letter from A to F. Tap a chip or type a letter — use a monospace view for centering.

Live result Top E · 5 rows · base 9 letters
    A
   ABA
  ABCBA
 ABCDCBA
ABCDEDCBA

Worked Walkthrough — Top = E (end = 4)

Trace padding, ascending half, and mirrored descending half for each row.

iSpacesAscendingMirrorPrinted row
04A(none)A
13ABAABA
22ABCBAABCBA
31ABCDCBAABCDCBA
40ABCDEDCBAABCDEDCBA

After ascending, k = i + 1, so n = k - 1 = i. The first --n lands on i - 1.

C Programs

Three complete programs: fixed A–E with a bridge variable, top-letter input with scanf, and an explicit mirror loop. Use View Output to reveal sample results.

Example 1 — Fixed A–E

Matches the reference logic using a bridge variable n = k - 1 to print the descending half.

c
#include <stdio.h>

int main(void) {
    int i, j, k, m, n;
    char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    for (i = 0; i <= 4; i++) {
        for (j = 4; j > i; j--)
            printf(" ");

        for (k = 0; k <= i; k++)
            printf("%c", alpha[k]);

        n = k - 1;
        for (m = 0; m < i; m++)
            printf("%c", alpha[--n]);

        printf("\n");
    }

    return 0;
}

How It Works

1. Pad for centering. Spaces run from 4 down while j > i.

2. Ascend to the peak. Print alpha[0..i] — when i = 2, that is ABC.

3. Bridge past the peak. After the ascending loop, k = i + 1, so n = k - 1 = i.

4. Mirror without a double center. Each --n prints the previous letter — for i = 2, that yields BA and the full row ABCBA.

Example 2 — Top Letter Input

The loops adapt to the new size automatically. Check scanf and validate a single A–Z character in real apps.

c
#include <stdio.h>

int main(void) {
    char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    char top;
    int end, i, j, k, m, n;

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

    end = top - 'A';

    for (i = 0; i <= end; i++) {
        for (j = end; j > i; j--)
            printf(" ");

        for (k = 0; k <= i; k++)
            printf("%c", alpha[k]);

        n = k - 1;
        for (m = 0; m < i; m++)
            printf("%c", alpha[--n]);

        printf("\n");
    }

    return 0;
}

How It Works

1. Scale with end. end = top - 'A' drives padding, ascending, and mirror loops together.

2. Same core. For top = C you get three centered rows ending at ABCBA.

3. Safer input tip. Prefer:

Safer input
if (scanf(" %c", &top) != 1 || top < 'A' || top > 'Z') {
    printf("Enter one letter from A to Z.\n");
    return 1;
}

Example 3 — Explicit Mirror Loop

Often easier to read: after printing A..i, loop p from i - 1 down to 0.

c
#include <stdio.h>

int main(void) {
    int end = 4;
    int i, j, k, p;
    char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    for (i = 0; i <= end; i++) {
        for (j = end; j > i; j--)
            printf(" ");

        for (k = 0; k <= i; k++)
            printf("%c", alpha[k]);

        for (p = i - 1; p >= 0; p--)
            printf("%c", alpha[p]);

        printf("\n");
    }

    return 0;
}

How It Works

1. Same three stages. Spaces, then ascending, then mirror — only the mirror syntax changes.

2. Peak stays unique. p starts at i - 1, so the center letter is never printed twice.

3. Same output. Matches the bridge-variable version exactly.

Edge Cases & Pitfalls

Check these before calling the solution done.

Mirror from i

Double center letter

If the descending loop starts at i instead of i - 1, you get ABCCBA. Skip the peak.

Spaces off

Left-aligned pyramid

Keep for (j = end; j > i; j--). Starting at end - 1 or using >= shifts the centering.

printf("\n") inside

Column of characters

If printf("\n") is inside any of the three loops, each character lands on its own line. Print cells until the row is done.

top = A

Single A

When end = 0, you print one row: A (no spaces, no mirror). A good sanity check.

Wrong n

Bridge off by one

After ascending, k is already i + 1. Use n = k - 1, then --n — not n = k.

scanf

Leading space in format

Use scanf(" %c", &top) so a leftover newline does not become your letter. Still validate A–Z.

Time and Space Complexity

ProgramTimeExtra space
Bridge variable (Examples 1–2)O(n²)O(1) (plus the fixed alphabet table)
Explicit mirror (Example 3)O(n²)O(1)

For n = end + 1 rows, each row prints O(n) spaces and letters — quadratic in n.

Key Takeaways

  • Rule: spaces + A..i + (i − 1)..A.
  • Skip the peak once: mirror starts at i - 1 (or --n after n = k - 1).
  • Break the row: call printf("\n") only after all three stages.
  • Complexity: O(n²) time; O(1) extra space.

One line: pad, print A up to the peak, then mirror back to A without reprinting the peak.

Frequently Asked Questions

It prints A..i ascending, then prints (i-1)..A descending. This mirrors the left half without repeating the center letter.
After the ascending loop, k is one past the peak letter. Setting n = k-1 makes n equal the peak, and then --n starts the descending half from the previous letter.
The padding shifts each row to the right so the pyramid is centered under the widest row.
O(n²) for n rows because each row prints O(n) spaces and letters.
After printing A..i, the mirror part starts from i-1 down to A. That avoids duplicating the peak letter.
Check scanf(" %c", &top) == 1, require a single A–Z character, and reject invalid input.
Ascending prints i+1 letters and descending prints i letters, so the row has 2i+1 letters before counting spaces.
Program 18 is another palindromic alphabet pyramid approach. This page follows the classic bridge-variable style with n = k-1 and --n.

Did you know?

Each row has three stages: leading spaces for centering, then letters A..i ascending, then letters (i-1)..A descending. The reference keeps a bridge variable n = k - 1 after the ascending loop and prints --n to avoid duplicating the center letter.

Next: Inverted V Alphabet Pattern

Flip the hollow V so the tip sits at the top and the legs open downward.

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