Symmetric Decreasing Alphabet Square in C

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

What You’ll Learn

Stay symmetric by printing a left half (E down to A) and a mirrored right half (B up to E). Each cell follows the same rule: if j > i print the column letter; otherwise print the current row floor i. Compare Program 21 (diamond symmetry) and Program 24 (palindrome triangles). Includes a live preview, worked C examples, edge cases, and complexity.

Shape Rule

Layered square

Borders stay high; interiors drop toward A.

Two Halves

Mirror

Left E..A, right B..E — A once in the center.

Floor Rule

j > i

Print column letter or row floor letter.

Fixed Width

2k+1

For A..E (k=4), every row has 9 letters.

Live Preview

Top letter

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

O(n²)

Complexity

n rows × O(n) cells each.

Introduction

A symmetric decreasing alphabet square prints fixed-width rows whose outer letters stay high while the interior floor drops from the top letter down to A, mirrored left and right.

In C you solve it with an alphabet array, a descending row floor, and two column scans that share the same j > i choice rule.

Why it matters?

It teaches mirrored scans, a shared cell rule, and how to keep a single center letter — skills that transfer to concentric squares and Program 29.

Key Highlights

Floor i

Drops E → A each row.

Mirror

Left half + right half.

j > i

Border vs interior choice.

One A

Right half starts at B.

In short: for each floor i from top down to A, 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 fixed-width symmetric square whose interior floor drops from the top letter down to A.

c
// Five 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

Inputs & Outputs

ItemTypeDescription
top / kchar / intTop letter; k = top - 'A' (4 for E). Rows = k+1.
Printed outputtextSymmetric layers of width 2k+1 with a dropping floor.

Minimal workflow

Pseudocode
k = top - 'A'
for i from k down to 0:          // row floor
    for j from k down to 0:      // left half
        print (j > i ? letter[j] : letter[i]) + " "
    for j from 1 to k:           // right half (skip 0)
        print (j > i ? letter[j] : letter[i]) + " "
    print newline

Approach comparison

ApproachIdeaBest for
Two mirrored scansLeft k..0 + right 1..k with j>iMatching this classic sample
Distance from centerprint letter by max(dx, dy) styleConcentric / diamond variants

⚡ Quick Reference

GoalPattern
Top letterchar k = 'E'; (or from scanf)
Rowsfor (i = k; i >= 'A'; --i)
Left halffor (j = k; j >= 'A'; --j) /* j>i ? j : i */
Right halffor (j = 'B'; j <= k; ++j) /* same rule */
Full diamond nextSee Program 29

📋 Left vs Right vs Floor Rule

Same row — four roles that build the layered square.

j = k..A
left

Descending half through the center A

j = B..k
right

Ascending mirror; skips duplicating A

j > i ? j : i
floor

Border letter vs row-floor letter

printf("\n")
break

Ends the row after both halves

Context

When This Pattern Shows Up

Reach for this when teaching mirrored scans and shared cell rules for layered squares.

  1. After simple pyramids

    Step up from prefixes to concentric-style layers.

  2. Mirror + condition drills

    Practice one rule reused on both halves.

  3. Bridge to Program 29

    Same row logic, then mirror upward for a full diamond.

  4. Index practice

    Map letters to array indexes and reuse them safely.

  5. Not a UI layout tool

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

Key benefit: one shared j > i rule on mirrored halves is the cleanest way to build layered alphabet squares without special-casing the center.

🔮 Live Preview

Choose a top letter from A to F and draw the symmetric decreasing alphabet square in the browser.

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

Live result
Press "Draw pattern".

Examples Gallery

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

📚 Getting Started

Print five layered rows from E down to the A-center floor.

Example 1 — Fixed A–E

Two symmetric scans per row with the same j > i check, matching the reference logic.

c
#include <stdio.h>

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

    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");
    }

    return 0;
}

How It Works

When i = 'C', columns where j > 'C' print E/D borders, and interior cells print C. The right half starts at 'B' so the center A is not duplicated on the last row.

📈 Practical Variant

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

Example 2 — Top Letter Input

Works for A..top with the same symmetric square. 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");
    }

    return 0;
}

How It Works

k = top scales both the floor loop and the two halves. Width becomes 2*(top-'A')+1 (5 letters for top = C).

⚡ Helper Style

Same shape with a shared print helper for both halves.

Example 3 — Helper Function

Often clearer to read: one function applies the floor rule so left and right loops stay thin.

c
#include <stdio.h>

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

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

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

    return 0;
}

How It Works

print_cell owns the j > i rule once. Left and right loops only decide which columns to visit.

🧠 How the Algorithm Prints Rows

1

Pick the top letter

Set k to the top letter (like 'E'). Every printed cell is a letter from 'A' through k.

Setup
2

Outer loop drops the floor each row

Row letter i runs from k down to 'A'. Smaller i means a deeper inner layer — think of i as the minimum letter allowed in that row.

Rows
3

Left half: E down to A

For columns j = k..'A', choose with j > i ? j : i. Borders stay high; interiors drop to the row floor.

Left
4

Right half: B up to E

Scan j = 'B'..k. Starting at 'B' avoids printing the center A twice. Total columns: 2*(k-'A')+1 (9 for A–E).

Right
=

Symmetry + layers

Each row is a symmetric layer around the center. As i decreases, the minimum letter moves inward (E → D → C → B → A) — O(n²) time.

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

Trace each row floor and the resulting 9-letter line.

iFloor letterPrinted row
4EE E E E E E E E E
3DE D D D D D D D E
2CE D C C C C C D E
1BE D C B B B C D E
0AE D C B A B C D E

Width is always 2×4+1 = 9. The last row is the full palindrome around a single A.

Use Cases

Where this layered alphabet square shows up beyond the homework prompt.

1. Layer Labs

Clearest demo of borders staying high while interiors drop.

Example: flip j > i to j >= i and watch layers shift.

2. Mirror Practice

Reuse one cell rule on left and right scans.

Example: start the right half at 0 and see a double A.

3. Index Mapping

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

Example: scale from E to H without rewriting loops.

4. Helper Extraction

Factor the floor rule into one function (Example 3).

Example: reuse print_cell for Program 29 later.

5. Complexity Intuition

Fixed width × n rows makes O(n²) easy to see.

Example: 5 rows × 9 cells = 45 prints.

6. Bridge to Program 29

Reuse this row logic, then mirror upward for a full diamond.

Example: continue to Program 29.

Pro Tip: say “left E..A, right B..E, print max of column and floor” before coding — that story prevents a duplicated center A.

Advantages

Why this pattern earns a spot after simpler pyramids and rotations.

  1. 1. Instant Visual Feedback

    A broken mirror or wrong floor shows up immediately.

  2. 2. One Shared Rule

    Both halves reuse the same j > i choice.

  3. 3. Scales Cleanly

    Change k and the whole square grows.

  4. 4. Reusable for Program 29

    The same row logic becomes half of a full diamond.

Pro Tip: learn the inline ternary version first; extract print_cell once the floor rule feels automatic.

Usage Tips

Small habits that keep layered alphabet squares clean.

  1. 1. Start the Right Half at 1

    Starting at 0 duplicates the center A.

  2. 2. Keep One Floor Rule

    Reuse j > i ? ('A' + j) : ('A' + i) on both halves.

  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. Expect Trailing Spaces

    The sample prints a space after every letter; trim if you need clean ends.

Pro Tip: if the last row shows ... A A B ..., the right half almost certainly started at j = 0.

Common Pitfalls

Mistakes that commonly break symmetric decreasing alphabet squares.

  1. 1. Starting the Right Half at 0

    Duplicates the center A.

    → Start the right scan at j = 1.

  2. 2. Wrong Floor Condition

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

    → Keep j > i ? j : i.

  3. 3. Mismatched k and Alphabet

    Hard-coding k = 'E' while reading a different top letter breaks the square.

    → Set k from the chosen top letter.

  4. 4. Unchecked scanf

    Empty or non-letter input leaves top invalid.

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

  5. 5. Ascending Outer Loop by Mistake

    Running i from 0 to k prints layers in reverse order.

    → Descend i from k down to 0.

Edge Cases

Check these inputs before calling the solution done.

top = A

Single letter

Output is just A (right half empty).

top = E

Classic sample

5 rows × width 9 through the A center.

top = C

Smaller square

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

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Duplicate the center on purpose

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

2. Extract print_cell

  • Use a helper (Example 3)
  • Keep both halves calling it

3. Scale to H

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

4. Continue to Program 29

  • Mirror this square into a full diamond
  • See Program 29

Notes

  • Two halves. Left E..A and right B..E keep a single center A.
  • The floor rule j > i ? ('A' + j) : ('A' + i) builds borders and interiors together.
  • Row width is always 2k + 1 (9 for A..E).
  • Program 29 reuses this row logic and mirrors it upward for a full diamond.

Quick Takeaway: drop the floor from top to A, print left then right with the same j > i rule, and skip duplicating the center.

⏱️ Time and Space Complexity

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

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

Wrap Up

🎉 Conclusion

The symmetric decreasing alphabet square is a small nested-loop exercise with lasting payoff: mirrored halves, a shared floor rule, and a single center A. Master the classic E…A sample, then try user input and the helper rewrite.

Practice the three examples above, then continue to Program 29’s reverse centered alphabet pyramid.

Drop the floor, print left then right with j > i, start the right half at 1, then break the line.

💡 Best Practices

✅ Do

  • Start the right half at j = 1
  • Reuse one j > i floor rule on both halves
  • Derive k from the top letter
  • Check scanf and require an A–Z top letter
  • State O(n²) when asked about complexity

❌ Don’t

  • Start the right half at 0 (duplicates A)
  • Hard-code k without updating the alphabet source
  • Ascend the outer floor loop for this sample
  • 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 symmetric decreasing alphabet square the beginner-friendly way.

5
Core concepts
> 02

Choice

j > i ? j : i

Code
1 03

Right

Start at B

Code
04

New line

Ends each row

I/O
O 05

Complexity

O(n²) time

Analysis

❓ Frequently Asked Questions

It prints the border letters when the column letter j is above the current row floor i; otherwise it prints i. This builds higher-letter borders with a flat interior.
The first loop scans E down to A. The second scans B up to E so the middle A is printed once and the row is mirrored.
For letters A..k, width is (k-A+1) + (k-A) = 2*(k-A)+1. For A..E, width is 9.
Pick a larger top letter (like H), set k to that letter, and keep the same loop structure.
O(n²) for n letters because there are n rows and each row prints O(n) cells.
Starting at A would print A again and duplicate the center. Starting at B mirrors the left half cleanly.
Use scanf(" %c", &top), require A–Z, and reject non-letters.
Program 29 reuses the same row logic while descending to A, then mirrors upward from B to E so you get a full reverse-centered diamond without duplicating the center row.

Did you Know? 🔊

Fix k at the top letter (E). Outer loop i goes from k down to A. Left half scans j = k..A; right half scans j = B..k so A appears once in the middle. Each position prints j when j > i, otherwise prints i.

Continue to Alphabet Pattern 29

Next up: reverse-centered alphabet pyramids / diamonds.

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