Shape Rule
Vertex at bottom
Two outer stars first; legs close to one tip star on the last row.

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.
Vertex at bottom
Two outer stars first; legs close to one tip star on the last row.
i = rows..1
Reverse the outer loop — that is the only change from Program 7.
j + k legs
Left j = rows..1, right k = 2..rows — unchanged bodies.
i == 1
Only the j loop prints the bottom vertex; k never equals 1.
1–14 rows
Pick a height and draw the hollow V instantly.
Diamond half
O(n²) time; lower half of Program 9’s hollow diamond.
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.
Countdown outer loops plus conditional printing complete the hollow-outline toolkit. Once “same inners, reverse i” clicks, diamonds become a short stacking exercise.
i from rows down to 1.
Left j block + right k block.
Bottom row: one star from j == 1.
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.
Given a positive integer rows, print a hollow upright V of * characters with rows lines and width 2 * rows - 1 (wide first, vertex last).
// First 5 rows (spaces shown as ·)
// *·······*
// ·*·····*·
// ··*···*··
// ···*·*···
// ····*···· | Item | Type | Description |
|---|---|---|
rows | int | Height of the V (typically ≥ 1). Line width is 2 * rows - 1. |
| Printed output | text | Hollow outline: wide legs first, single tip last; interior spaces. |
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 | Idea | Best for |
|---|---|---|
| Countdown + if/else | Same as Program 7; reverse outer | Learning and interviews |
| Ternary shortcut | Same loops; i == j ? "*" : " " | Shorter demos after conditions click |
| Goal | Pattern |
|---|---|
| Walk rows wide → tip | for (i = rows; i >= 1; i--) |
| Left leg columns | for (j = rows; j >= 1; j--) + if (i == j) |
| Right leg columns | for (k = 2; k <= rows; k++) + if (i == k) |
| Line width | 2 * rows - 1 |
| Flip to inverted V | for (i = 1; i <= rows; i++) (see Program 7) |
| Ternary form | printf("%s", (i == j) ? "*" : " "); |
Same inner equality tests — outer-loop direction and stacking define the family.
i = 1..rowsInverted V — apex on top
i = rows..1Upright V — vertex at bottom
+ upper halfHollow diamond — this page as lower half
solid fillInverted pyramid — stars, not outline
Reach for an upright hollow V when teaching countdown loops after the inverted hollow V.
Natural “change one loop” follow-up once the inverted V clicks.
for (i = n; i >= 1; i--) with conditional printing.
Filled under Program 7 for Program 9.
Same countdown idea; Program 6 fills stars instead of outlining.
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.
Choose a height between 1 and 14 and draw the hollow upright V in the browser.
Three complete C programs — countdown if/else legs, console input, and a ternary shortcut. Click View Output to reveal sample console results.
Print a five-row hollow upright V with nested loops and if/else.
rows = 5Outer loop counts down; left j = rows..1; right k = 2..rows; star when indices match.
#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;
} 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).
Let the user choose the height at runtime.
Read rows with scanf("%d", &rows) (check the return value in real apps).
#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;
} 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.
Same outline with ternary operators instead of multi-line if/else.
? : FormKeep both loops and the countdown; compress the star-vs-space choice into one expression each.
#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;
} 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.
Set rows. Use i counting down, j for the left block, k for the right block.
for (i = rows; i >= 1; i--) — widest legs when i == rows, tip when i == 1.
for (j = rows; j >= 1; j--) with if (i == j) draws the left diagonal as i shrinks.
for (k = 2; k <= rows; k++) with if (i == k), then printf("\n"). No star when i == 1.
Vertex at the bottom, opening upward. O(n²) time, O(1) extra space. Width 2n - 1.
rows = 4Trace where each star lands as i counts down from 4 to 1 (line width = 7).
i | Left star (j) | Right star (k) | Stars on row | Printed row |
|---|---|---|---|---|
4 | j == 4 | k == 4 | 2 | * * |
3 | j == 3 | k == 3 | 2 | * * |
2 | j == 2 | k == 2 | 2 | * * |
1 | j == 1 | none (k starts at 2) | 1 | * |
Same star positions as Program 7 — only print order is reversed. The tip row still has a single star.
Where this hollow V (and countdown outlining) shows up beyond the homework prompt.
One formula pair, two shapes — inverted V vs upright V.
Example: flip Program 7’s outer loop only.
Stack under Program 7 (often from rows - 1).
Example: Program 9.
Change to i = 1..rows to restore Program 7.
Example: Program 7.
Program 6 fills every star; this page keeps only the outline.
Example: side-by-side for rows = 5.
Print i instead of * at match positions.
Example: visualize which row owns each star.
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.
Why the upright hollow V is a favorite follow-up pattern.
Reuse known legs; only reverse i.
Wrong direction instantly prints an inverted V instead.
Pair with Program 7 for hollow diamonds.
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.
Small habits that keep hollow-V code clean.
rows, Step Downi++ by mistake reprints Program 7.
k Starting at 2Needed so the tip row stays a single vertex star.
scanf’s return valueAvoid crashes when the user types letters instead of a number.
Skipping the else branch collapses columns and ruins the V.
Trace rows = 4 countdown on paper before larger demos.
Pro Tip: if the tip prints first, you almost certainly used i++ instead of i--.
Mistakes that commonly break hollow V patterns.
for (i = 1; i <= rows; i++) reprints the inverted V.
→ Use for (i = rows; i >= 1; i--).
When i == 1, only the j loop can match — k starts at 2.
→ Treat the tip as a single vertex by design.
Columns collapse; the V becomes a left-aligned smear.
→ Always print " " when the equality fails.
Alignment looks fine in one editor and broken in another.
→ Always print the space character " ".
Failed scanf leaves rows uninitialized.
→ Check scanf’s return value and re-prompt on failure.
Check these inputs before calling the solution done.
One iteration: left loop prints one *; right loop never runs.
Outer loop never runs — print nothing or show a message.
rows < 0Treat as invalid; re-prompt instead of silent empty output.
Top width 2n-1 — fine for labs; may wrap on tiny terminals.
Failed scanf leaves rows unset — check its return value.
i == rowsStars at both outer columns — widest gap of the upright V.
Try these variations to lock in the pattern.
i = 1..rowsi == 1 prints only one stark never equals 1i instead of * at match positionsrows - 12 * rows - 1 characters wide.i == 1), which has 1 — total stars = 2 * rows - 1.rows > 0 for interactive programs; rows = 1 prints a single vertex.Quick Takeaway: countdown i from rows to 1, print * when i equals the column index in each leg — that is the upright hollow V.
| Program | Time | Extra 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.
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.
k = 2scanf’s return value for interactive demosi when you meant an upright Vi == 1 tip rowrows = 1 vertex edge casePrint the upright outline the beginner-friendly way.
Countdown + match indices
Definitioni = rows..1
DirectionSame as Prog 7
LegsOne star only
VertexO(n²) time
AnalysisThis 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.
Stack the inverted V and upright V halves to build a full hollow diamond outline.
12 people found this page helpful