Shape Rule
Apex on top
One star on row 1; two stars farther apart on each row below.

A hollow inverted V starts with one apex star and widens: each row prints at most two stars via if (i == j) and if (i == k), with spaces everywhere else. This tutorial covers both legs, why k starts at 2, a live preview, algorithm steps, worked C examples, edge cases, and complexity.
Apex on top
One star on row 1; two stars farther apart on each row below.
j = rows..1
Print * only when i == j; otherwise a space.
k = 2..rows
Mirror slant; start at 2 so the apex is not duplicated.
2n - 1
Left block rows + right block rows - 1 characters.
1–14 rows
Pick a height and draw the hollow inverted V instantly.
Diamond half
O(n²) time; upper half of Program 9’s hollow diamond.
A hollow inverted V draws only the outline: one apex on top, then two stars per row that drift farther apart toward the base.
Unlike solid pyramids, every cell chooses * or space from an equality test. Flip the outer loop in Program 8 for an upright V, or stack both halves for the hollow diamond.
Conditional printing (if star else space) is the core skill behind hollow shapes. Once i == j / i == k clicks, diamonds and banners become composition problems.
Left j block + right k block.
Star only when row equals column index.
Prevents a double apex on row 1.
Building block for Program 9.
In short: for each row i, 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 inverted V of * characters with rows lines and width 2 * rows - 1.
// First 5 rows (spaces shown as ·)
// ····*····
// ···*·*···
// ··*···*··
// ·*·····*·
// *·······* | Item | Type | Description |
|---|---|---|
rows | int | Height of the inverted V (typically ≥ 1). Line width is 2 * rows - 1. |
| Printed output | text | Hollow outline: stars on diagonals only; interior spaces. |
for i from 1 to rows:
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 |
|---|---|---|
| Two loops + if/else | Left and right segments separately | Learning and interviews |
| Ternary shortcut | Same loops; i == j ? "*" : " " | Shorter demos after conditions click |
| Goal | Pattern |
|---|---|
| Walk each row | for (i = 1; i <= rows; 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 upright V | for (i = rows; i >= 1; i--) (see Program 8) |
| 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
+ lower halfHollow diamond — this page on top
solid fillInverted pyramid — stars, not outline
Reach for a hollow inverted V when teaching conditional printing after solid pyramids.
Natural step once Programs 5–6 are solid.
if star else space is a classic nested-loop interview warm-up.
Upper half of Program 9’s hollow diamond.
Matching row and column indices builds 2D thinking.
Terminal teaching pattern — not how you build app screens.
Key benefit: one outline that locks in star-vs-space decisions — the gateway to hollow diamonds.
Choose a height between 1 and 14 and draw the hollow inverted V in the browser.
Three complete C programs — classic if/else legs, console input, and a ternary shortcut. Click View Output to reveal sample console results.
Print a five-row hollow inverted V with nested loops and if/else.
rows = 5Left loop j = rows..1; right loop k = 2..rows; star when indices match.
#include <stdio.h>
int main(void) {
int i, j, k;
int rows = 5;
for (i = 1; i <= rows; ++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 = 1, only j == 1 prints a star — the apex. When i = 5, stars land at the outer columns of both blocks. 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 = 1; i <= rows; ++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 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; 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 = 1; i <= rows; ++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 for the row, j for the left block, k for the right block.
for (i = 1; i <= rows; i++) — apex when i == 1, widest gap when i == rows.
for (j = rows; j >= 1; j--) with if (i == j) draws the descending left diagonal.
for (k = 2; k <= rows; k++) with if (i == k), then printf("\n"). Start at 2 to skip a duplicate apex.
Only diagonal positions get *. O(n²) time, O(1) extra space. Width 2n - 1.
rows = 4Trace where each star lands for every outer-loop value of i (line width = 7).
i | Left star (j) | Right star (k) | Stars on row | Printed row |
|---|---|---|---|---|
1 | j == 1 | none (k starts at 2) | 1 | * |
2 | j == 2 | k == 2 | 2 | * * |
3 | j == 3 | k == 3 | 2 | * * |
4 | j == 4 | k == 4 | 2 | * * |
Row 1 is the only single-star line — that is why the right loop must not start at k = 1.
Where this hollow inverted V (and diagonal conditions) shows up beyond the homework prompt.
Every cell is an explicit star-or-space decision.
Example: dry-run i == j on paper for rows = 4.
Reuse this body, then add Program 8 from rows - 1.
Example: Program 9.
Countdown outer loop keeps the same inners.
Example: Program 8.
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 “star when i equals the column index” before coding — that is the whole outline rule.
Why the hollow inverted V is a favorite mid-series pattern.
Equality tests make outline vs fill an explicit choice.
Wrong k start or loop order looks obviously broken.
Same legs power Program 8 and Program 9.
Every row is 2n-1 chars — easy to verify alignment.
Pro Tip: master the if/else version first; treat ternaries as a polish shortcut afterward.
Small habits that keep hollow-outline code clean.
k Starting at 2Starting at 1 duplicates the apex on row 1.
j From rowsThis pattern assumes j walks rows → 1 for the left leg.
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 star positions before coding larger demos.
Pro Tip: if row 1 shows two stars side by side, you almost certainly started k at 1.
Mistakes that commonly break hollow inverted V patterns.
k at 1Duplicates the apex: row 1 prints two stars.
→ Use for (k = 2; k <= rows; k++).
j Instead of DescendingWrong column order shifts or mirrors the left leg.
→ Keep for (j = rows; j >= 1; j--).
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.
Left loop prints one *; right loop (k = 2..1) never runs.
Outer loop never runs — print nothing or show a message.
rows < 0Treat as invalid; re-prompt instead of silent empty output.
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 inverted V.
Try these variations to lock in the pattern.
i = rows..1k at 1k = 2i instead of * at match positionsrows - 1 down to 12 * rows - 1 characters before the newline.2 * rows - 1.rows > 0 for interactive programs; rows = 1 prints a single centered-looking apex in a 1-char line.Quick Takeaway: print * when i equals the column index in each leg — left j = rows..1, right k = 2..rows.
| 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. Only 2n - 1 stars are printed, but every cell is visited.
The hollow inverted V is conditional printing on two legs: star when i matches the column index, space otherwise. Keep k starting at 2, and the apex stays a single star — flip the outer loop next for an upright V or stack halves for a diamond.
Practice the three examples above, then continue to the V-shaped hollow pattern.
Left descends, right starts at 2, width = 2n−1 — keep the equality tests, and validate row counts when reading input.
k = 22 * rows - 1scanf’s return value for interactive demosk at 1 without adjusting the conditionj without checking the left-leg shaperows = 1 apex edge casePrint the outline the beginner-friendly way.
Star iff indices match
Definitionj = rows..1
Legk = 2..rows
Leg2n - 1
LayoutO(n²) time
AnalysisThis hollow inverted V is the upper half of the hollow diamond. Starting the right loop at k = 2 is deliberate: on row 1 the left loop already prints the apex, so k = 1 would duplicate that star.
Keep the same inner loops and count the outer loop down for an upright V with a bottom vertex.
12 people found this page helpful