Inverted V-Shaped Alphabet Pattern in C

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

What You’ll Learn

Draw a letter V that opens toward the bottom: one A on the first row, then pairs B B, C C, and so on, with gaps growing in the middle. Two inner loops fill a fixed grid with spaces except on two diagonals.

Contrast with program 31 (normal V, wide at the top) and program 32 (filled palindrome pyramid).

⭐ Pattern Output

Five rows; each full line is 5 + 4 = 9 characters (leading and trailing spaces matter in the console):

Output
    A    
   B B   
  C   C 
 D     D 
E       E
1

Complete C Program ('A''E')

First block: j from 69 down to 65. Second block: k from 66 through 69 only.

c
#include <stdio.h>

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

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

    return 0;
}

🧠 How It Works

1

Outer i walks the alphabet upward

i is both the row index and the letter that should appear on the two arms for that row. Growing i widens the hollow inverted V until the bottom row shows the full span.

i
2

Left pass: j from top letter down to A

For each column code j, print the letter only if i == j; otherwise print a space. Because j moves from high to low, the visible letter slides left as i increases.

j
3

Right pass: k from B up to the top letter

The second loop mirrors the first on the right side. Starting k at B avoids a duplicate A on row A; for larger i both passes can emit the same letter, giving the paired columns in the output.

k
4

Why the middle looks empty

Most pairs (i, j) and (i, k) fail the equality test, so you print spaces. Only the two diagonal hits become letters, which leaves a growing gap between the arms.

·
=

Two prints per wide row

When i >= 'B', the same code point satisfies both i == j and i == k, so you see two letters on that row. Two full inner scans per outer row → O(n²) for n letters in the range.

2

Variation — User Input

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

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

    return 0;
}

💡 Tips for Enhancement

Try These

  • Rewrite with 'A''E' as character bounds for i, j, and k
  • Fill the interior between the legs for a solid downward triangle
  • Stretch the V with double spaces in each loop body

Avoid

  • Starting the second loop at startChar unless you want two As on row one
  • Non-monospace output; alignment will look broken

Key Takeaways

1

Two conditional inner loops; letters appear only where indices match the row letter.

2

Right loop begins at startChar + 1 so the apex row is a single character.

3

Line width is 2n - 1 character prints for n letters (n left block + n - 1 right block).

4

O(n²) time for n rows.

❓ Frequently Asked Questions

The left loop paints one diagonal; the right loop paints a parallel diagonal offset by one column index range. From B downward both hit the same letter, so the two arms move apart as i increases.
Order only affects where each space or letter lands in the line. You could reverse either loop if you permute how columns map to positions; this version matches the usual “left block then right block” layout.
You print 9 × 5 = 45 characters, not 5² = 25. Big-O is still O(n²) because each row does Theta(n) work for n rows.
O(n²) for n rows from A through the last letter.

More Alphabet Patterns

Diagonal and V patterns are the same idea: choose which column indices may print on each row.

All Alphabet Patterns →
Did you know?

If the second loop started at 'A', row A would satisfy i == k twice across the two blocks and you would see two As unless you change the ranges.

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