V-Shaped Hollow Star Pattern in C

Beginner
⏱️ 10 min read
📚 Updated: Aug 2026
🎯 3 Code Examples
🚀 Live Preview
i from rows to 1

What You’ll Learn

An upright hollow V reuses Program 7’s legs — if (i == j) and if (i == k) — but runs the outer loop from rows down to 1 so the wide row prints first and the legs close at a bottom vertex. This tutorial covers reverse iteration, why the tip is a single star, a live preview, algorithm steps, worked C examples, edge cases, and complexity.

Shape Rule

Vertex at bottom

Two outer stars first; legs close to one tip star on the last row.

Countdown

i = rows..1

Reverse the outer loop — that is the only change from Program 7.

Same Inners

j + k legs

Left j = rows..1, right k = 2..rows — unchanged bodies.

Single Tip

i == 1

Only the j loop prints the bottom vertex; k never equals 1.

Live Preview

1–14 rows

Pick a height and draw the hollow V instantly.

O(n²)

Diamond half

O(n²) time; lower half of Program 9’s hollow diamond.

Introduction

A hollow V opens wide at the top and closes to a single vertex at the bottom — only outline stars, spaces everywhere else.

It is the flip of Program 7: keep the same j/k equality tests, reverse only the outer loop. Stack both halves for the hollow diamond.

Why it matters?

Countdown outer loops plus conditional printing complete the hollow-outline toolkit. Once “same inners, reverse i” clicks, diamonds become a short stacking exercise.

Key Highlights

Reverse Outer

i from rows down to 1.

Same Two Legs

Left j block + right k block.

Single Vertex

Bottom row: one star from j == 1.

Diamond Lower Half

Building block for Program 9.

In short: for i from rows down to 1, scan left columns j = rows..1 and right columns k = 2..rows; print * when the column index equals i, else a space.

📝 Problem & Approach

Given a positive integer rows, print a hollow upright V of * characters with rows lines and width 2 * rows - 1 (wide first, vertex last).

c
// First 5 rows (spaces shown as ·)
// *·······*
// ·*·····*·
// ··*···*··
// ···*·*···
// ····*····

Inputs & Outputs

ItemTypeDescription
rowsintHeight of the V (typically ≥ 1). Line width is 2 * rows - 1.
Printed outputtextHollow outline: wide legs first, single tip last; interior spaces.

Minimal workflow

Pseudocode
for i from rows down to 1:
    for j from rows down to 1:
        print "*" if i == j else " "
    for k from 2 to rows:
        print "*" if i == k else " "
    print newline

Approach comparison

ApproachIdeaBest for
Countdown + if/elseSame as Program 7; reverse outerLearning and interviews
Ternary shortcutSame loops; i == j ? "*" : " "Shorter demos after conditions click

⚡ Quick Reference

GoalPattern
Walk rows wide → tipfor (i = rows; i >= 1; i--)
Left leg columnsfor (j = rows; j >= 1; j--) + if (i == j)
Right leg columnsfor (k = 2; k <= rows; k++) + if (i == k)
Line width2 * rows - 1
Flip to inverted Vfor (i = 1; i <= rows; i++) (see Program 7)
Ternary formprintf("%s", (i == j) ? "*" : " ");

📋 V vs Inverted V vs Hollow Diamond

Same inner equality tests — outer-loop direction and stacking define the family.

Program 7
i = 1..rows

Inverted V — apex on top

This page
i = rows..1

Upright V — vertex at bottom

Program 9
+ upper half

Hollow diamond — this page as lower half

Program 6
solid fill

Inverted pyramid — stars, not outline

Context

When This Pattern Shows Up

Reach for an upright hollow V when teaching countdown loops after the inverted hollow V.

  1. After Program 7

    Natural “change one loop” follow-up once the inverted V clicks.

  2. Countdown practice

    for (i = n; i >= 1; i--) with conditional printing.

  3. Hollow diamond lower half

    Filled under Program 7 for Program 9.

  4. Compare with Program 6

    Same countdown idea; Program 6 fills stars instead of outlining.

  5. Not a UI layout tool

    Terminal teaching pattern — not how you build app screens.

Key benefit: proves that flipping a hollow outline is one outer-loop change — the gateway to stacking diamond halves.

🔮 Live Preview

Choose a height between 1 and 14 and draw the hollow upright V in the browser.

Try 4, 5, or 7. Each line width will be 2 * rows - 1.

Live result
Press "Draw pattern".

Examples Gallery

Three complete C programs — countdown if/else legs, console input, and a ternary shortcut. Click View Output to reveal sample console results.

📚 Getting Started

Print a five-row hollow upright V with nested loops and if/else.

Example 1 — Fixed rows = 5

Outer loop counts down; left j = rows..1; right k = 2..rows; star when indices match.

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

When i = 5, stars land at both outer columns. When i = 1, only j == 1 prints a star — the bottom vertex. Each line is 9 characters wide (2 * 5 - 1).

📈 Practical Variant

Let the user choose the height at runtime.

Example 2 — User Input Version

Read rows with scanf("%d", &rows) (check the return value in real apps).

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

How It Works

Same countdown left/right leg core as Example 1; only the source of rows changes. Non-numeric input leaves rows unset if you ignore scanf’s return value — always check it in safer labs.

⚡ Shortcut Style

Same outline with ternary operators instead of multi-line if/else.

Example 3 — Ternary ? : Form

Keep both loops and the countdown; compress the star-vs-space choice into one expression each.

c
#include <stdio.h>

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

    for (i = rows; i >= 1; --i) {
        for (j = rows; j >= 1; --j) {
            printf("%s", (i == j) ? "*" : " ");
        }
        for (k = 2; k <= rows; ++k) {
            printf("%s", (i == k) ? "*" : " ");
        }
        printf("\n");
    }

    return 0;
}

How It Works

Same bounds and conditions as Example 1; only the print statement is shorter. Keep the if/else version for exams that want the branch structure spelled out.

🧠 How the Algorithm Prints Rows

1

Set up

Set rows. Use i counting down, j for the left block, k for the right block.

Setup
2

Outer loop (reverse)

for (i = rows; i >= 1; i--) — widest legs when i == rows, tip when i == 1.

Direction
3

Left leg

for (j = rows; j >= 1; j--) with if (i == j) draws the left diagonal as i shrinks.

Left
4

Right leg then newline

for (k = 2; k <= rows; k++) with if (i == k), then printf("\n"). No star when i == 1.

Right
=

Hollow V

Vertex at the bottom, opening upward. O(n²) time, O(1) extra space. Width 2n - 1.

🔎 Worked Walkthrough — rows = 4

Trace where each star lands as i counts down from 4 to 1 (line width = 7).

iLeft star (j)Right star (k)Stars on rowPrinted row
4j == 4k == 42*     *
3j == 3k == 32 *   * 
2j == 2k == 22  * *  
1j == 1none (k starts at 2)1   *   

Same star positions as Program 7 — only print order is reversed. The tip row still has a single star.

Use Cases

Where this hollow V (and countdown outlining) shows up beyond the homework prompt.

1. Teaching Loop Direction

One formula pair, two shapes — inverted V vs upright V.

Example: flip Program 7’s outer loop only.

2. Hollow Diamond Lower Half

Stack under Program 7 (often from rows - 1).

Example: Program 9.

3. Flip Back to Inverted V

Change to i = 1..rows to restore Program 7.

Example: Program 7.

4. Compare With Solid Pyramid

Program 6 fills every star; this page keeps only the outline.

Example: side-by-side for rows = 5.

5. Numbered Diagonals

Print i instead of * at match positions.

Example: visualize which row owns each star.

6. Input Validation Labs

Pair with a scanf return-value check and positive-row checks.

Example: reject rows <= 0 and re-prompt.

Pro Tip: say “Program 7 inners, countdown outer” before coding — that is the whole design.

Advantages

Why the upright hollow V is a favorite follow-up pattern.

  1. 1. Minimal Diff From Program 7

    Reuse known legs; only reverse i.

  2. 2. Clear Countdown Feedback

    Wrong direction instantly prints an inverted V instead.

  3. 3. Completes Diamond Halves

    Pair with Program 7 for hollow diamonds.

  4. 4. Same Complexity Story

    Same O(n²) visit cost as Program 7 — order does not change big-O.

Pro Tip: master the nested-loop countdown first; treat ternaries as a polish shortcut afterward.

Usage Tips

Small habits that keep hollow-V code clean.

  1. 1. Start at rows, Step Down

    i++ by mistake reprints Program 7.

  2. 2. Keep k Starting at 2

    Needed so the tip row stays a single vertex star.

  3. 3. Check scanf’s return value

    Avoid crashes when the user types letters instead of a number.

  4. 4. Always Print Spaces

    Skipping the else branch collapses columns and ruins the V.

  5. 5. Dry-Run One Small n

    Trace rows = 4 countdown on paper before larger demos.

Pro Tip: if the tip prints first, you almost certainly used i++ instead of i--.

Common Pitfalls

Mistakes that commonly break hollow V patterns.

  1. 1. Incrementing Instead of Decrementing

    for (i = 1; i <= rows; i++) reprints the inverted V.

    → Use for (i = rows; i >= 1; i--).

  2. 2. Expecting Two Stars on the Tip Row

    When i == 1, only the j loop can match — k starts at 2.

    → Treat the tip as a single vertex by design.

  3. 3. Omitting the else Space Branch

    Columns collapse; the V becomes a left-aligned smear.

    → Always print " " when the equality fails.

  4. 4. Mixing Tabs With Spaces

    Alignment looks fine in one editor and broken in another.

    → Always print the space character " ".

  5. 5. Blind scanf

    Failed scanf leaves rows uninitialized.

    → Check scanf’s return value and re-prompt on failure.

Edge Cases

Check these inputs before calling the solution done.

rows = 1

Single vertex

One iteration: left loop prints one *; right loop never runs.

rows = 0

Empty pattern

Outer loop never runs — print nothing or show a message.

Negative

rows < 0

Treat as invalid; re-prompt instead of silent empty output.

Large n

Wide first line

Top width 2n-1 — fine for labs; may wrap on tiny terminals.

Bad input

Non-numeric scanf

Failed scanf leaves rows unset — check its return value.

First row

i == rows

Stars at both outer columns — widest gap of the upright V.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Flip back to Program 7

  • Change outer loop to i = 1..rows
  • Confirm inverted V with apex on top

2. Trace the tip row

  • Show why i == 1 prints only one star
  • Confirm k never equals 1

3. Print row numbers

  • Write i instead of * at match positions
  • Check that diagonals show decreasing values

4. Build a hollow diamond

  • Print Program 7, then this body from rows - 1
  • Match Program 9

Notes

  • Same totals as Program 7. Order changes; every row is still 2 * rows - 1 characters wide.
  • Star count is 2 on every row except the tip (i == 1), which has 1 — total stars = 2 * rows - 1.
  • Validate rows > 0 for interactive programs; rows = 1 prints a single vertex.
  • Next: Program 9 stacks both halves into a hollow diamond.

Quick Takeaway: countdown i from rows to 1, print * when i equals the column index in each leg — that is the upright hollow V.

⏱️ Time and Space Complexity

ProgramTimeExtra space
Two inner loops + if/else (Examples 1–2)O(rows²)O(1)
Ternary shortcut (Example 3)O(rows²)O(1)

Each of n rows runs Θ(n) iterations across left + right blocks. Same as Program 7.

Wrap Up

🎉 Conclusion

The hollow upright V is Program 7 with a countdown outer loop: same i == j / i == k legs, printed from wide to tip. Keep k starting at 2 so the vertex stays a single star — then stack with Program 7 for a diamond.

Practice the three examples above, then continue to the hollow diamond.

Countdown outer, same legs, tip is one star — keep i--, and validate row counts when reading input.

💡 Best Practices

✅ Do

  • Explain “Program 7 inners + countdown outer” before coding
  • Start the right loop at k = 2
  • Print a space whenever the equality fails
  • State that the tip row has one star by design
  • Check scanf’s return value for interactive demos

❌ Don’t

  • Increment i when you meant an upright V
  • Expect two stars on the i == 1 tip row
  • Skip spaces so columns collapse
  • Ignore bad console input in user-facing demos
  • Skip the rows = 1 vertex edge case

Key Takeaways

Knowledge Unlocked

Five things to remember about the hollow V

Print the upright outline the beginner-friendly way.

5
Core concepts
02

Outer

i = rows..1

Direction
= 03

Inners

Same as Prog 7

Legs
1 04

Tip

One star only

Vertex
O 05

Complexity

O(n²) time

Analysis

❓ Frequently Asked Questions

Program 7 runs i from 1 to rows (inverted V: narrow top). Program 8 runs i from rows down to 1 with the same inner loops, so the first line uses i equal rows and prints stars at both outer columns. As i decreases, both legs move inward until the last line has a single bottom vertex.
Only the outer loop direction changes. Program 7 uses i from 1 to rows. Program 8 uses i from rows to 1. The conditions i equals j and i equals k are the same.
When i is 1, the first inner loop still prints a star at j equals 1. The second loop runs k from 2 to rows, so i equals k never holds. The right leg does not add a second star on that row.
Each line has width 2 * rows - 1 characters — same geometry as Program 7, only the row order is reversed.
With n rows, each row does Theta(n) iterations across the two inner loops, so the time complexity is O(n²).
This page is the lower half of Program 9. Stack Program 7 on top (then this body from rows-1 down to 1) to complete the diamond.
Yes. printf("%s", (i == j) ? "*" : " ") and the same for k — same loops, shorter print statements.
Check scanf's return value: if (scanf("%d", &rows) != 1) handle bad input. Unchecked scanf leaves rows uninitialized on failure.

Did you Know? 🔊

This hollow V is exactly Program 7 with the outer loop reversed — the same trick as Program 5 versus Program 6. It is the lower half of the hollow diamond. The bottom vertex is a single star because k starts at 2.

Continue to Hollow Diamond

Stack the inverted V and upright V halves to build a full hollow diamond outline.

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