C Inverted V Alphabet Pattern

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

What Is This Pattern?

An inverted V-shaped alphabet pattern prints a single A at the top, then letter pairs that open downward (B B, C   C, …) with spaces everywhere else.

Remember
Rule: left n..0 when i==j; right 1..n when i==k

    A
   B B
  C   C
 D     D
E       E         ← tip A once (end = 'E')

The right scan starts at 1 (not 0) so the tip A prints once. It is the upside-down cousin of Program 31; Program 34 stacks this shape with its mirror to make a diamond.

How to Solve It

Two ways to emit the same inverted V — inline diagonal checks, or a shared print_cell helper.

MethodIdeaBest for
Two scans inlineLeft n..0, right 1..n, print when row == colLearning, interviews, exams
print_cell helperOne function owns the diagonal rule for both legsCleaner demos once the tip skip clicks

Pseudocode

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

Cheat sheet

GoalPattern
End indexint n = end - 'A'; (4 for E)
Rowsfor (i = 0; i <= n; i++)
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] : ' ');
Single tip ARight scan starts at 1, not 0
Width(n + 1) + n = 2n + 1
Normal VSee Program 31

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 scans finish a row
putchar(ch)Same as printing one characterOptional leaner style once loops click

Live Preview

Change the end letter and the inverted V updates instantly — width is always 2n + 1, with a single A on the first row.

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

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

Worked Walkthrough — End = E (n = 4)

Trace each row’s diagonal hits and the resulting 9-column line.

iLeft hitRight hitPrinted row
0A at j=0(none)A
1B at j=1B at k=1B B
2C at j=2C at k=2C C
3D at j=3D at k=3D D
4E at j=4E at k=4E E

Width is always 2×4 + 1 = 9. The tip row has no right-leg match because k never equals 0.

C Programs

Three complete programs: fixed A–E, end-letter input with scanf, and a helper-function rewrite. Use View Output to reveal sample results.

Example 1 — Fixed A–E

Left scan runs from E..A, then right scan runs from B..E.

c
#include <stdio.h>

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

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

    return 0;
}

How It Works

1. Outer loop picks the row. i runs from 0 to 4 (letters A…E).

2. Left leg — reverse scan. Scan j = 4..0; print the letter only when i == j, else a space.

3. Right leg — skip A. Scan k = 1..4; print when i == k. Starting at 1 skips a second tip A.

4. Tip row. When i = 0, only the left scan can print A.

Example 2 — End Letter Input

The left scan is end..A and the right scan is B..end. 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");
    }

    return 0;
}

How It Works

1. Scale with n. n = end - 'A' drives both scans. For end = C, width is 2×2 + 1 = 5.

2. Same tip rule. Right loop still starts at 1 so the tip is a single A.

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 Function

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

c
#include <stdio.h>

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

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

    for (i = 0; i <= n; i++) {
        for (j = n; j >= 0; j--)
            print_cell(alpha, i, j);

        for (k = 1; k <= n; k++)
            print_cell(alpha, i, k);

        printf("\n");
    }

    return 0;
}

How It Works

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

2. Tip still skipped on the right. The right loop starts at 1 even with the helper.

Edge Cases & Pitfalls

Check these before calling the solution done.

k = 0

Double tip A

If the right scan includes index 0, the first row prints A twice. Keep for (k = 1; k <= n; k++).

No spaces

Collapsed shape

Writing only letters packs both legs together. Non-hits must print ' '.

printf("\n") inside

Column of cells

If printf("\n") is inside either scan, each cell lands on its own line. Print cells with %c; break the line only after both scans.

end = A

Single A

When n = 0, left prints A and the right loop never runs. A good sanity check.

Left 0..n

Wrong left direction

Scanning left 0..n instead of n..0 still hits the diagonal but shifts column order — keep the reverse scan for the classic layout.

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 scans inline (Examples 1–2)O(n²)O(1) (plus the fixed alphabet table)
Helper function (Example 3)O(n²)O(1)

About n + 1 rows × 2n + 1 characters printed per row — still quadratic in n.

Key Takeaways

  • Rule: print a letter only when row index equals column index.
  • Single tip A: right scan starts at 1, not 0.
  • Spaces keep the shape: non-hits print ' '; break the row with printf("\n") after both scans.
  • Complexity: O(n²) time; O(1) extra space.

One line: for each row, scan left n..0 and right 1..n, printing a letter only on the diagonal.

Frequently Asked Questions

Because the right block starts from B, so it never matches i = 0 (A). Only the left block prints A on the first row.
Width is 2n+1: n+1 columns from the left block and n columns from the right block. For A–E, n is 4 and width is 9.
Program 31 is wide at the top and has a single bottom vertex. Program 33 has a single A at the top and widens downward with pairs like B B, C C.
O(n²) because there are n+1 rows and each row scans O(n) positions across both blocks.
Spaces keep column alignment so the two diagonals open into a visible inverted V in a monospace console.
Check scanf(" %c", &end) == 1, require a single A–Z character, and reject invalid input.
Yes. Set n = end − 'A', scan j from n down to 0 on the left, and scan k from 1 to n on the right.
Program 34 reuses this inverted-V row logic for A..E, then mirrors D..A downward to close a full diamond without repeating the widest E row.

Did you know?

Two blocks per row. Left block scans E down to A and prints only when i == j. Right block scans B up to E and prints only when i == k. Because the right block never visits A, the first row prints a single A, while later rows print the same letter twice and the shape opens downward.

Next: Diamond Alphabet Pattern

Stack this inverted V with its mirror (D..A) to close a full diamond without repeating the widest row.

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