Diamond-Shaped Alphabet Pattern in C

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

What You’ll Learn

Build a full diamond by stacking the inverted V from Program 33 (A..E) and then mirroring it back (D..A). The only extra trick: start the bottom half from D so the widest row (E) is printed only once. Compare Program 31 (normal V) and Program 21 (other diamond ideas). Includes a live preview, worked C examples, edge cases, and complexity.

Two Phases

Top + mirror

A..E up, then D..A down — one widest row.

Same Row Rule

From Prog 33

Left n..0, right 1..n, print when i == col.

Skip Center

Start at n-1

Bottom half begins at D to avoid a double E.

2n+1 Rows

Closed diamond

For A..E (n=4), nine rows of width 9.

Live Preview

End letter

Pick an end letter (A–F) and draw the diamond.

O(n²)

Complexity

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

Introduction

A diamond-shaped alphabet pattern opens from a tip A down to a widest letter, then closes symmetrically back to A — two inverted-V halves sharing one middle row.

In C you reuse Program 33’s diagonal scans for both phases, and start the second outer loop at n - 1 so the widest row appears once.

Why it matters?

It teaches composing a closed shape from a reusable row printer and skipping a duplicated center — the same composition skill used in many diamond labs.

Key Highlights

Top

Rows A → E.

Bottom

Rows D → A.

i == col

Shared diagonal rule.

One E row

Bottom starts at D.

In short: for each i in 0..n then n-1..0, scan left n..0 and right 1..n, printing when i == col, then call printf("\n").

📝 Problem & Approach

Given an end letter (or fixed E), print a diamond: Program 33’s inverted V through the widest letter, then the matching rows back down without repeating the middle.

c
// Nine rows (end = E, width 9)
//     A
//    B B
//   C   C
//  D     D
// E       E
//  D     D
//   C   C
//    B B
//     A

Inputs & Outputs

ItemTypeDescription
end / nchar / intEnd letter; n = end - 'A' (4 for E). Rows = 2n+1.
Printed outputtextFull diamond of width 2n+1 with letters on diagonals.

Minimal workflow

Pseudocode
n = end - 'A'
printRows(i from 0 to n)           // top incl. widest
printRows(i from n-1 down to 0)    // bottom, skip widest

printRows(i):
    for j from n down to 0:        // left
        print (i == j ? letter[j] : " ")
    for k from 1 to n:             // right (skip A)
        print (i == k ? letter[k] : " ")
    print newline

Approach comparison

ApproachIdeaBest for
Two-phase outer loopsTop 0..n + bottom (n-1)..0 with shared row printerMatching this classic sample
Distance from centerMap row to letter by abs distance from middleOne outer loop; same visuals

⚡ Quick Reference

GoalPattern
Alphabet + nchar alpha[] = "ABCDEFG..."; int n = 4;
Top halffor (int i = 0; i <= n; i++) print_row(...);
Bottom halffor (int i = n - 1; i >= 0; i--) print_row(...);
Left / rightj = n..0 then k = 1..n with i == col ? alpha[col] : ' '
Top half onlySee Program 33

📋 Top vs Bottom vs Row Rule

Four roles that close the diamond without a double widest row.

i = 0..n
top

Grows to the widest letter

i = n-1..0
bottom

Mirrors back; skips duplicating E

i == col
diag

Same cell rule as Program 33

printf("\n")
break

Ends each full-width row

Context

When This Pattern Shows Up

Reach for this when closing Program 33’s inverted V into a full diamond.

  1. After Program 33

    Reuse the same row printer; add the bottom phase.

  2. Two-phase loop drills

    Practice ascending then descending without a double center.

  3. Helper extraction

    Factor print_row once and call it from both phases.

  4. Series finale

    Caps the alphabet-pattern set before number patterns.

  5. Not a UI layout tool

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

Key benefit: one shared Program 33 row rule plus a bottom half that starts at n - 1 is the cleanest way to close an inverted V into a diamond.

🔮 Live Preview

Choose an end letter from A to F and draw the diamond-shaped alphabet pattern in the browser.

Try E (classic sample) or C (smaller diamond). Preview allows A–F. Use a monospace view for alignment.

Live result
Press "Draw pattern".

Examples Gallery

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

📚 Getting Started

Print nine diamond rows from tip A through widest E and back to A.

Example 1 — Fixed A–E

Two phases with identical inner loops; the second phase starts at D to avoid duplicating the E row.

c
#include <stdio.h>

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

    /* Top half: A through E */
    for (i = 0; i <= 4; i++) {
        for (j = 4; j >= 0; j--) {
            if (i == j)
                printf("%c", alpha[j]);
            else
                printf(" ");
        }
        for (k = 1; k <= 4; k++) {
            if (i == k)
                printf("%c", alpha[k]);
            else
                printf(" ");
        }
        printf("\n");
    }

    /* Bottom half: D through A (avoid repeating E row) */
    for (i = 3; i >= 0; i--) {
        for (j = 4; j >= 0; j--) {
            if (i == j)
                printf("%c", alpha[j]);
            else
                printf(" ");
        }
        for (k = 1; k <= 4; k++) {
            if (i == k)
                printf("%c", alpha[k]);
            else
                printf(" ");
        }
        printf("\n");
    }

    return 0;
}

How It Works

The upper loop mirrors Program 33 through the widest E row. The lower loop starts at i = 3 (D) so that middle line is not printed twice.

📈 Practical Variant

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

Example 2 — End Letter Input

Build the top half (A..end) then mirror back (end-1..A). Check scanf and validate a single A–Z character in real apps.

c
#include <stdio.h>

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

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

    n = end - 'A';

    for (i = 0; i <= n; i++) {
        for (j = n; j >= 0; j--)
            printf("%c", i == j ? alpha[j] : ' ');
        for (k = 1; k <= n; k++)
            printf("%c", i == k ? alpha[k] : ' ');
        printf("\n");
    }

    for (i = n - 1; i >= 0; i--) {
        for (j = n; j >= 0; j--)
            printf("%c", i == j ? alpha[j] : ' ');
        for (k = 1; k <= n; k++)
            printf("%c", i == k ? alpha[k] : ' ');
        printf("\n");
    }

    return 0;
}

How It Works

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

⚡ Helper Style

Same diamond with shared print_cell and print_row helpers.

Example 3 — Helper Functions

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

c
#include <stdio.h>

void print_cell(char alpha[], int row, int col) {
    printf("%c", row == col ? alpha[col] : ' ');
}

void print_row(char alpha[], int n, int i) {
    int j, k;

    for (j = n; j >= 0; j--)
        print_cell(alpha, i, j);
    for (k = 1; k <= n; k++)
        print_cell(alpha, i, k);
    printf("\n");
}

int main() {
    char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int n = 4;
    int i;

    for (i = 0; i <= n; i++)
        print_row(alpha, n, i);

    for (i = n - 1; i >= 0; i--)
        print_row(alpha, n, i);

    return 0;
}

How It Works

print_cell owns the row == col 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 33 row logic

Each row prints a left diagonal via a reverse scan (n..0) and a right diagonal via a forward scan (1..n), printing only when i == col.

Logic
2

Top half grows A..E

Outer loop prints rows for i = 0..n — this is exactly Program 33.

Top
3

Bottom half mirrors D..A

Start at n - 1 (D for E) so the widest row is not duplicated.

Mirror
4

Width and rows are both 2n+1

Left has n+1 columns and right has n columns. Total rows: (n+1) + n = 2n+1 (9 for A..E).

Shape
=

Top + mirror = diamond

Build the top half from A to E, then mirror back down from D to A — O(n²) time.

🔎 Worked Walkthrough — End = E (n = 4)

Trace each phase, row index, and resulting 9-column line.

PhaseiLetterPrinted row
Top0AA
Top1BB B
Top2CC C
Top3DD D
Top4EE E
Bottom3DD D
Bottom2CC C
Bottom1BB B
Bottom0AA

Width is always 2×4+1 = 9. Total rows are 2×4+1 = 9. The widest E row appears only once (top phase).

Use Cases

Where this diamond alphabet pattern shows up beyond the homework prompt.

1. Composition Labs

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

Example: start bottom at n and watch a double E row.

2. Symmetry Practice

Top and bottom floors mirror around the widest letter.

Example: compare row i=2 top with i=2 bottom.

3. Index Mapping

Practice n = end - '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 writes for A..E.

6. Bridge from Program 33

Top half is Program 33; bottom half closes the diamond.

Example: revisit Program 33.

Pro Tip: say “print Program 33, then floors (n-1)..0 with the same row” before coding — that story prevents a duplicated widest row.

Advantages

Why this pattern earns a spot as the alphabet-pattern series finale.

  1. 1. Instant Visual Feedback

    A double widest row or broken diagonal shows up immediately.

  2. 2. Reuses Program 33

    No new cell rule — only a second outer phase.

  3. 3. Scales Cleanly

    Change n and the whole diamond grows.

  4. 4. Helper-Friendly

    print_row keeps both phases short and readable.

Pro Tip: master Program 33 first; this page is mostly “call that row again while climbing down from n-1.”

Usage Tips

Small habits that keep diamond alphabet patterns clean.

  1. 1. Start the Bottom Half at n-1

    Starting at n duplicates the widest row.

  2. 2. Keep the Right Leg Starting at 1

    Same tip rule as Program 33 on every row.

  3. 3. Set n from the End Letter

    Use n = end - 'A' so scaling stays automatic.

  4. 4. Check scanf

    Require a single A–Z character; use toupper 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 widest rows appear, the bottom half almost certainly started at i = n.

Common Pitfalls

Mistakes that commonly break diamond alphabet patterns.

  1. 1. Starting the Bottom Half at n

    Duplicates the widest row.

    → Start the bottom phase at i = n - 1.

  2. 2. Starting the Right Leg at 0

    Duplicates the tip A on tip rows.

    → Start the right scan at k = 1.

  3. 3. Skipping Spaces

    Writing only letters collapses the diamond.

    → Print a space whenever row != col.

  4. 4. Unchecked scanf

    Empty or multi-character input leaves end unused or only takes the first char.

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

  5. 5. Forgetting the Bottom Phase

    Stopping after the first loop leaves only Program 33’s inverted V.

    → Add for (i = n - 1; i >= 0; i--) with the same row printer.

Edge Cases

Check these inputs before calling the solution done.

end = A

Single letter

Output is just A (bottom half empty).

end = E

Classic sample

9 rows × width 9 through the E middle.

end = C

Smaller diamond

5 rows × width 5 (Example 2).

Lowercase

Case mismatch

Convert lowercase with toupper from <ctype.h> if needed.

Bad input

Empty / multi-char

Check scanf’s return value before using end.

Debug dots

See columns

Temporarily print . instead of spaces.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Duplicate the center on purpose

  • Start the bottom half at n once
  • Confirm why the sample starts at n-1

2. Extract print_row

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

3. Scale to H

  • Set end = H and recompute n
  • Check rows = width = 2n+1

4. Compare with Program 33

Notes

  • Two phases. Top 0..n then bottom (n-1)..0 keep a single widest row.
  • The diagonal rule i == col is identical to Program 33.
  • Row width and row count are both 2n + 1 (9 for A..E).
  • Next up in the C series: number pattern tutorials.

Quick Takeaway: print Program 33’s rows through the widest letter, then the same rows from n-1 down to 0, with one shared diagonal 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+1 letters there are 2n+1 rows and each row scans O(n) columns, so total work is O(n²).

Wrap Up

🎉 Conclusion

The diamond-shaped alphabet pattern is Program 33 closed into a diamond: the same diagonal row rule, plus a bottom phase that starts at n-1 so the widest row appears once. Master the classic A…E…A sample, then try user input and the helper rewrite.

Practice the three examples above, then continue to C number pattern programs.

Top 0..n, bottom (n-1)..0, same left/right diagonal scans, then break each line.

💡 Best Practices

✅ Do

  • Start the bottom half at i = n - 1
  • Start the right half at k = 1
  • Reuse one i == col diagonal rule on both halves
  • Derive n from the end letter
  • State O(n²) when asked about complexity

❌ Don’t

  • Start the bottom half at n (duplicates the widest row)
  • Hard-code n without updating the alphabet source
  • Change the diagonal rule between phases
  • Skip validating end-letter input
  • Call printf("\n") inside either half loop

Key Takeaways

Knowledge Unlocked

Five things to remember about this alphabet pattern

Print the diamond-shaped alphabet pattern the beginner-friendly way.

5
Core concepts
= 02

Choice

i == col

Code
1 03

Bottom

Start at n-1

Code
R 04

Rows

2n+1 total

Shape
O 05

Complexity

O(n²) time

Analysis

❓ Frequently Asked Questions

The first outer loop grows i from A through E using the inverted-V inner loops. The second outer loop shrinks i from D through A with the same inner loops, mirroring the top without repeating the E row.
Because the widest E row is already printed at the end of the first part. Starting the second part at endChar-1 avoids duplicating the center row.
Yes. Program 34 is Program 33 printed for A..E and then mirrored back for D..A using the same inner loops.
O(n²) for n letters because there are about (2n−1) rows and each row prints O(n) characters.
For n letters, width is 2n−1: n columns from the left block and n−1 columns from the right block.
Total rows are 2n−1 (9 rows for A..E): n rows upward through the widest letter, then n−1 mirrored rows back down.
Check scanf(" %c", &end) == 1, require a single A–Z character, and reject invalid input.
Same reason as Program 33: skipping A keeps a single tip letter on the top (and bottom) row instead of printing A twice.

Did you Know? 🔊

Two phases with identical inner loops. Phase 1 prints A..E using two diagonal scans (left: E..A, right: B..E). Phase 2 prints D..A to mirror the top without repeating the widest E row. For n letters, total rows are 2n-1 and width is also 2n-1.

Continue to C Number Patterns

You finished the alphabet pattern series. Next up: nested-loop number patterns with the same tutorial style.

Number Patterns hub →

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