Inverted V-Shaped Alphabet Pattern in C

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

What You’ll Learn

Draw an inverted V: one A at the top, then pairs like B B, C C, widening as you go down. Scan a fixed-width row and print letters only where the row index matches the column index. Compare Program 31 (normal V) and Program 34 (full diamond). Includes a live preview, worked C examples, edge cases, and complexity.

Opens Down

Inverted V

Single A at the tip; pairs widen downward.

Left Scan

n..0

Print when i == j; else space.

Skip A Right

k = 1..n

Right leg starts at B so the tip stays single.

Width 2n+1

(n+1) + n

For A..E (n=4), each line spans 9 columns.

Live Preview

End letter

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

O(n²)

Complexity

n rows × O(n) column scans each.

Introduction

An inverted V-shaped alphabet pattern places a single tip letter at the top and then prints matching letter pairs that move farther apart on each lower row.

In C you walk row index i, scan left columns from n down to 0, then scan right columns from 1 to n, printing only when i matches the column.

Why it matters?

It is the natural mirror of Program 31 and the top half of Program 34’s diamond — so learning it once pays off twice.

Key Highlights

Left leg

Scan n..0 with i == j.

Right leg

Scan 1..n; skip tip A.

Spaces

Fill non-diagonal cells.

One tip

Top A prints once.

In short: for each row i, scan left n..0 printing when i == j, then scan right 1..n printing when i == k, then call printf("\n").

📝 Problem & Approach

Given an end letter (or fixed E), print an inverted V of letters on two diagonals with spaces elsewhere and a single top tip.

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

Inputs & Outputs

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

Minimal workflow

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

Approach comparison

ApproachIdeaBest for
Two diagonal scansLeft n..0 + right 1..n with i==colMatching this classic sample
Flip of Program 31Same rule; opposite opening directionComparing normal V vs inverted V

⚡ Quick Reference

GoalPattern
Alphabet + nchar alpha[] = "ABCDEFG..."; int n = 4;
Rowsfor (int i = 0; i <= n; i++)
Left legfor (int j = n; j >= 0; j--) printf("%c", i == j ? alpha[j] : ' ');
Right legfor (int k = 1; k <= n; k++) printf("%c", i == k ? alpha[k] : ' ');
Normal VSee Program 31
Full diamond nextSee Program 34

📋 Left vs Right vs Tip

Four roles that open the inverted V without a double A.

j = n..0
left

Reverse scan; prints when i == j

k = 1..n
right

Forward scan; skips tip A

spaces
fill

Keep columns aligned

printf("\n")
break

Ends each full-width row

Context

When This Pattern Shows Up

Reach for this when teaching sparse diagonals that open downward from a single tip.

  1. After Program 31

    Flip the V: tip at the top instead of the bottom.

  2. Diagonal condition drills

    Practice i == j with spaces for alignment.

  3. Tip handling

    Skip A on the right so the top prints once.

  4. Bridge to Program 34

    Reuse this row logic, then mirror downward for a diamond.

  5. Not a UI layout tool

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

Key benefit: left scan n..0 plus right scan 1..n is the cleanest way to open an inverted V with a single tip A.

🔮 Live Preview

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

Try E (classic sample) or C (smaller shape). 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 a print_cell helper. Click View Output to reveal sample console results.

📚 Getting Started

Print a five-row inverted V with a single A at the tip.

Example 1 — Fixed A–E

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

c
#include <stdio.h>

int main() {
    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

When i = 2, the left scan prints C while scanning down, and the right scan prints C when k = 2. On the first row, only the left scan can print A.

📈 Practical Variant

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

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

    return 0;
}

How It Works

n = end - 'A' scales both scans. For end = C, width is 2×2+1 = 5 and the tip is a single A.

⚡ Helper Style

Same inverted V with a shared cell helper for both legs.

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

print_cell owns the row == col rule once. The right loop still starts at 1 to keep a single tip A.

🧠 How the Algorithm Prints Rows

1

Each row chooses a letter

Row index i runs 0..n, representing A..end (A..E when n = 4).

Rows
2

Left leg (reverse scan)

Scan j = n..0. Print the letter only when i == j; otherwise print a space.

Left
3

Right leg (skip A)

Scan k = 1..n (B..E). Skipping A ensures the first row prints only one A.

Right
4

Width stays 2n+1

Left block has n+1 columns; right block has n columns. Total width is 2n+1 (9 for A..E).

Width
=

Two slanted sides

Letters appear only on matching diagonals; everything else is a space — O(n²) time.

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

Use Cases

Where this inverted V alphabet pattern shows up beyond the homework prompt.

1. Diagonal Labs

Clearest demo of letter pairs that open downward.

Example: temporarily print . instead of spaces to see columns.

2. Tip Practice

Learn why the right leg must skip A.

Example: start right at 0 and watch a double A.

3. Compare with Program 31

Same diagonal idea; opposite opening direction.

Example: place both outputs side by side.

4. Helper Extraction

Factor the diagonal rule into print_cell (Example 3).

Example: reuse print_cell for Program 34 later.

5. Complexity Intuition

Full grid scans make O(n²) easy to see even when few letters print.

Example: 5 rows × 9 cells = 45 writes.

6. Bridge to Program 34

Reuse this row logic, then mirror D..A for a diamond.

Example: continue to Program 34.

Pro Tip: say “left n..0, right 1..n, spaces elsewhere” before coding — that story prevents a double tip A.

Advantages

Why this pattern earns a spot right after the normal V.

  1. 1. Instant Visual Feedback

    A broken diagonal or double tip shows up immediately.

  2. 2. Reuses Program 31 Skills

    Same i == col rule; only scan directions change.

  3. 3. Scales Cleanly

    Change n and the whole inverted V grows.

  4. 4. Reusable for Program 34

    This row logic becomes the top half of the diamond.

Pro Tip: check alignment in a monospace font; proportional fonts make spaces look uneven.

Usage Tips

Small habits that keep inverted V alphabet patterns clean.

  1. 1. Start the Right Leg at 1

    Starting at 0 duplicates the tip A.

  2. 2. Always Print Spaces Off-Diagonal

    Skipping spaces collapses the shape into packed letters.

  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. Check in Monospace

    Proportional fonts hide whether columns really align.

Pro Tip: if the first row shows A A, the right scan almost certainly started at k = 0.

Common Pitfalls

Mistakes that commonly break inverted V alphabet patterns.

  1. 1. Starting the Right Leg at 0

    Duplicates the tip A on the first row.

    → Start the right scan at k = 1.

  2. 2. Skipping Spaces

    Writing only letters collapses the inverted V.

    → Print a space whenever row != col.

  3. 3. End Letter Past Z

    Char math can walk past the alphabet.

    → Validate a single A–Z letter.

  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. Using Program 31’s Scan Directions

    Left 0..n and right (n-1)..0 draw a normal V, not this inverted one.

    → Keep left n..0 and right 1..n for this page.

Edge Cases

Check these inputs before calling the solution done.

end = A

Single letter

Output is just A (right leg empty).

end = E

Classic sample

5 rows × width 9 opening to E E.

end = C

Smaller shape

3 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 tip on purpose

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

2. Extract print_cell

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

3. Scale to H

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

4. Continue to Program 34

  • Mirror this shape into a full diamond
  • See Program 34

Notes

  • Two legs. Left n..0 and right 1..n form the inverted V.
  • Print letters only when row == col; otherwise print a space.
  • Row width is always 2n + 1 (9 for A..E).
  • Program 34 reuses this logic and mirrors D..A to close a diamond.

Quick Takeaway: scan left n..0 with i == j, scan right 1..n with i == k, fill spaces, keep one tip A, then break the line.

⏱️ 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+1 letters there are n+1 rows and each row scans O(n) columns across both blocks, so total work is O(n²).

Wrap Up

🎉 Conclusion

The inverted V-shaped alphabet pattern is Program 31 flipped: a single tip at the top and letter pairs that open downward. Master the classic A…E sample, then try user input and the helper rewrite.

Practice the three examples above, then continue to Program 34’s diamond-shaped alphabet pattern.

Left n..0 with i == j, right 1..n with i == k, spaces elsewhere, then break the line.

💡 Best Practices

✅ Do

  • Start the right leg at k = 1
  • Print spaces on non-diagonal cells
  • Derive n from the end letter
  • Validate a single A–Z end letter for input variants
  • State O(n²) when asked about complexity

❌ Don’t

  • Start the right leg at 0 (duplicates tip A)
  • Skip spaces and pack letters together
  • Hard-code n without updating the alphabet source
  • Skip validating end-letter input
  • Call printf("\n") inside either column loop

Key Takeaways

Knowledge Unlocked

Five things to remember about this alphabet pattern

Print the inverted V-shaped alphabet pattern the beginner-friendly way.

5
Core concepts
= 02

Condition

i == col

Code
1 03

Right

Start at B

Code
W 04

Width

2n+1 columns

Shape
O 05

Complexity

O(n²) time

Analysis

❓ 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 columns from the left block and n−1 columns from the right block.
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 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.

Continue to Alphabet Pattern 34

Next up: diamond-shaped alphabet patterns that reuse this inverted V for A..E, then mirror D..A 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