C Diamond Alphabet Pattern

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

What Is This Pattern?

A diamond-shaped alphabet pattern prints only the outline of a diamond: tip A at the top, letters that open to a wide waist, then close back to tip A.

Remember
Rule: upper i = 0..n, then lower i = n−1..0
      On each row, print alpha[col] where i == col

    A
   B B
  C   C
 D     D
E       E
 D     D
  C   C
   B B
    A         ← A–E (9 rows, width 9)

Build it by stacking Program 33 (upper inverted V) and mirroring back from n − 1 so the waist prints once. Geometry matches the hollow diamond in Star Pattern 9, with letters instead of *.

How to Solve It

Print one hollow alphabet row with two inner loops, then call that idea twice — ascending, then descending past the waist.

MethodIdeaBest for
Dual outer loopsUpper 0..n, lower n−1..0, same j/k bodiesLearning, interviews, clearest stack of P33
print_row helperOne print_row(i) called from both halvesLess duplication once the geometry clicks

Pseudocode

Pseudocode
n = end - 'A'
print_row(i, n):
    for j from n down to 0:
        print alpha[j] if i == j else ' '
    for k from 1 to n:
        print alpha[k] if i == k else ' '
    print newline

for i from 0 to n:          // upper half
    print_row(i, n)
for i from n - 1 down to 0: // lower half (skip waist)
    print_row(i, n)

Cheat sheet

GoalPattern
End indexint n = end - 'A'; (4 for E)
Upper phasefor (i = 0; i <= n; i++) print_row(...);
Lower phasefor (i = n - 1; i >= 0; i--) print_row(...);
Left legfor (j = n; j >= 0; j--) printf("%c", i == j ? alpha[j] : ' ');
Right legfor (k = 1; k <= n; k++) printf("%c", i == k ? alpha[k] : ' ');
Skip waist twiceLower starts at n - 1, not n
SizeRows = width = 2n + 1
Upper half onlyProgram 33

Printing Letters vs Starting a New Line

APIEffectUse for
printf("%c", ...)Stays on the same lineEach letter or space cell
printf("\n")Ends the current lineAfter both half-loops of a row
putchar(ch)Same as printing one characterOptional leaner style once loops click

Live Preview

Change the end letter and the hollow diamond updates instantly — rows = width = 2n + 1.

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

Live result End E · 9 rows · width 9
    A
   B B
  C   C
 D     D
E       E
 D     D
  C   C
   B B
    A

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

C Programs

Three complete programs: fixed A–E, end-letter input with scanf, and print_cell / print_row helpers. Use View Output to reveal sample results.

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(void) {
    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

1. Upper phase. Floor i runs from 0 to 4 — same as Program 33 through the widest E row.

2. Lower phase. Floor i runs from 3 to 0 so the waist line is not printed twice.

3. Same row body. Both phases use left n..0 and right 1..n with i == col.

4. Single tips. Right scan starts at 1, so top and bottom rows show one A each.

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(void) {
    char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    char end;
    int n, i, j, k;

    printf("Enter end 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

1. Scale with n. n = end - 'A' drives both phases. For end = C you get 5 rows of width 5 (2n + 1).

2. Same skip rule. Lower phase still starts at n - 1.

3. Safer input tip. Prefer:

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

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(void) {
    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

1. print_cell owns the rule. row == col lives in one place.

2. print_row owns both halves. Left n..0 and right 1..n, then printf("\n").

3. Thin phases. The two outer loops only decide which floors to visit.

Edge Cases & Pitfalls

Check these before calling the solution done.

i = n

Duplicate waist

If the lower phase starts at n, the widest row prints twice. Keep for (i = n - 1; i >= 0; i--).

k = 0

Double tip A

The right half of each row must start at 1, same as Program 33.

printf("\n") inside

Column of cells

If printf("\n") is inside either half-loop, each cell lands on its own line. Break the line only after both halves.

end = A

Single A

When n = 0, upper prints A and lower never runs. A good sanity check.

Upper only

Program 33 by mistake

Forgetting the lower phase leaves an open inverted V. Add for (i = n - 1; i >= 0; i--) with the same row printer.

scanf

Leading space in format

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

Time and Space Complexity

ProgramTimeExtra space
Two phases inline (Examples 1–2)O(n²)O(1) (plus the fixed alphabet table)
Helper functions (Example 3)O(n²)O(1)

For n = end - 'A' there are 2n + 1 rows of width 2n + 1 — still quadratic in n. Roughly twice Program 33’s cell count, minus one shared waist row.

Key Takeaways

  • Rule: same print_row as Program 33 — upper 0..n, lower n−1..0.
  • No double waist: lower phase starts at n − 1.
  • Break the row: call printf("\n") only after both half-loops.
  • Complexity: O(n²) time; O(1) extra space.

One line: print Program 33’s rows from 0 to n, then again from n − 1 down to 0.

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 n−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 = end − 'A' because there are 2n+1 rows and each row prints O(n) characters.
For n = end − 'A', width is 2n+1: n+1 columns from the left block and n columns from the right block. For A–E, width is 9.
Total rows are 2n+1 (9 when n = 4): n+1 rows upward through the widest letter, then n 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 = end - 'A', total rows and width are both 2n + 1.

Next: Number Pattern Programs

You finished the C alphabet series — continue with number patterns using the same nested-loop skills.

Number patterns →

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