V-Shaped Alphabet Pattern in C

Beginner
⏱️ 7 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Nested Loops

What You’ll Learn

Print letters only where the row letter i matches the column letter j or k; everywhere else print a space. The two diagonals form a V (like the letter): wide at the top with A on both sides, meeting at the bottom row’s vertex letter.

This is not the same as program 33 (inverted V, wide at the bottom). Related idea: program 30 stitches two runs on one row; here each leg is mostly blanks.

⭐ Pattern Output

Five rows, 5 + 4 = 9 characters wide (trailing spaces on the last row may be invisible in some viewers):

Output
A       A
 B     B
  C   C
   D D
    E
1

Complete C Program ('A''E')

ASCII 6569; second loop ends at 65 with start 68 ('D').

c
#include <stdio.h>

int main() {
    int i, j, k;

    for (i = 65; i <= 69; ++i) {
        for (j = 65; j <= 69; ++j) {
            if (i == j) {
                printf("%c", j);
            } else {
                printf(" ");
            }
        }
        for (k = 68; k >= 65; --k) {
            if (i == k) {
                printf("%c", k);
            } else {
                printf(" ");
            }
        }
        printf("\n");
    }

    return 0;
}

🧠 How It Works

1

Row index i

Also the letter code for that row: A through E.

i
2

Left leg i == j

j scans the alphabet left to right; the match hits the descending diagonal of the combined picture.

j
3

Right leg i == k

k runs DA; same row letter, mirrored positions.

k
4

Vertex row

When i == E, only the left loop can match; the right loop prints spaces only—the tip of the V is a single letter.

E
=

Spacing

Leading spaces before the first letter grow row by row; the two arms move toward the center.

2

Variation — User Input

endChar = (char)('A' + rows - 1); right loop k from endChar - 1 down to startChar.

c
#include <stdio.h>

int main() {
    int rows;
    int i, j, k;
    char startChar, endChar;

    printf("Enter the number of rows: ");
    scanf("%d", &rows);

    startChar = 'A';
    endChar = (char)('A' + rows - 1);

    for (i = startChar; i <= endChar; ++i) {
        for (j = startChar; j <= endChar; ++j) {
            if (i == j) {
                printf("%c", j);
            } else {
                printf(" ");
            }
        }
        for (k = endChar - 1; k >= startChar; --k) {
            if (i == k) {
                printf("%c", k);
            } else {
                printf(" ");
            }
        }
        printf("\n");
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Double the horizontal gap with " " instead of one space
  • Star version: print * on diagonals with the same i == j tests in a square matrix
  • Odd-sized alphabet blocks keep one center letter on the last row

Avoid

  • Running k through endChar unless you redesign width (can duplicate the bottom vertex)
  • Proportional fonts—alignment disappears

Key Takeaways

1

Two scans per row; only equality tests pick out diagonal cells.

2

Right loop length n - 1 keeps total width 2n - 1.

3

Same i is compared to both j and k; the printed character equals i when matched.

4

O(n²) for n rows.

❓ Frequently Asked Questions

For i == 'E' you would print another E in the right block, widening the line and breaking the single vertex at the tip of the V. Starting at endChar - 1 matches the reference layout.
No: five rows times nine prints is 45, while 5² = 25. Complexity is still O(n²) when the alphabet has n letters because each row does Theta(n) work.
Yes: map a single index to either the left column letter or the right segment letter and apply the same i equality rules.
O(n²) for n letters from A to the top letter.

Explore More C Alphabet Patterns!

Diagonal patterns are just equality checks between row and column indices dressed as letters.

All Alphabet Patterns →
Did you know?

On row i, at most two cells print letters—one from each inner loop—except you only see one on the bottom row because the right scan never reaches i.

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