V-Shaped Hollow Star Pattern in C

Beginner
⏱️ 7 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
i from rows to 1

What You'll Learn

How to get an upright V from the same inner logic as Program 7 (inverted V): keep the j and k loops and if (i == j) / if (i == k) tests, but drive i from rows down to 1 so the wide row prints first and the legs close to the bottom vertex. Each line remains 2 * rows - 1 characters wide (9 when rows = 5).

On the last row (i == 1), only the j-loop prints the single vertex star; the k-loop prints spaces only.

⭐ Pattern Output

When you run the program with rows = 5 (each line is 9 characters):

Output
*       *
 *     * 
  *   *  
   * *   
    *    
1

Complete C Program

Fixed rows = 5 version:

c
#include <stdio.h>

int main(void) {
    int i, j, k;
    int rows = 5;

    for (i = rows; i >= 1; --i) {
        for (j = rows; j >= 1; --j) {
            if (i == j) {
                printf("*");
            } else {
                printf(" ");
            }
        }
        for (k = 2; k <= rows; ++k) {
            if (i == k) {
                printf("*");
            } else {
                printf(" ");
            }
        }
        printf("\n");
    }

    return 0;
}

🧠 How It Works

1

Outer loop (reverse rows)

for (i = rows; i >= 1; --i) prints the widest row first (i == rows) and the single-star bottom row last (i == 1).

Order
2

Left segment (j)

for (j = rows; j >= 1; --j): print * if i == j, else space. That draws the left leg of the V for every i.

Left leg
3

Right segment (k)

for (k = 2; k <= rows; ++k) mirrors the rule on the right. When i == 1 (bottom vertex), this loop only prints spaces—the single star came from the j pass.

Right leg
4

New line & width

printf("\n") after both segments. Line length is still 2 * rows - 1 characters; reversing the outer i order flips which row is widest.

println
=

Wide top, narrow bottom

Same j/k rules as the inverted V, but i counts down so the opening faces up. O(rows²) output, O(1) extra space; wide rows scroll in the preview on small viewports.

2

Variation — User Input Version

Use scanf for rows:

c
#include <stdio.h>

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

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

    for (i = rows; i >= 1; --i) {
        for (j = rows; j >= 1; --j) {
            if (i == j) {
                printf("*");
            } else {
                printf(" ");
            }
        }
        for (k = 2; k <= rows; ++k) {
            if (i == k) {
                printf("*");
            } else {
                printf(" ");
            }
        }
        printf("\n");
    }

    return 0;
}

💡 Tips for Enhancement

Try These

  • Switch the outer loop to 1..rows to recover Program 7 (inverted V)
  • Validate rows >= 1 after input
  • Stack Program 7 (inverted V) then Program 8 (upright V), or see Program 9 for the full hollow diamond
  • Print row index i where stars appear

Avoid

  • Claiming two stars on the bottom row from both loops—only j hits i == 1
  • Incrementing i in the outer loop (that produces Program 7’s inverted V, not this upright V)
  • Omitting spaces so columns no longer align

Key Takeaways

1

Same inner logic as Program 7 (inverted V); only outer loop direction changes to flip the shape upright.

2

Top row (i == rows): stars at j == rows and k == rows.

3

Bottom row (i == 1): one star from j; k loop is all spaces.

4

Line width remains 2 * rows - 1 characters.

5

Time complexity O(n²) for n rows.

❓ Frequently Asked Questions

Large i values run first, so the row with two outer stars (i == rows) is printed before smaller i values pull the legs inward.
Program 7 uses for (i = 1; i <= rows; ++i) (inverted V, narrow top). Program 8 uses for (i = rows; i >= 1; --i) (upright V, vertex at bottom). The j and k loops and the if conditions are the same.
For i == 1, the right loop only considers k >= 2, so i == k never holds. The bottom vertex is the lone * from j == 1, plus padding spaces to the right.
O(n²) for n rows, same as Program 7.

Explore More C Star Patterns!

Pair inverted V (Program 7) and upright V (Program 8) to build hollow diamonds and hourglass shapes.

All Star Patterns →
Did you know?

This is the same trick as Program 6 versus Program 5: reverse the outer row index while keeping the per-row formulas unchanged.

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