V-Shaped Hollow Star Pattern in C#

What You'll Learn
How to get an upright hollow 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 at 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 bottom vertex star; the k-loop prints spaces only.
⭐ Pattern Output
When you run the program with rows = 5 (each line is 9 characters):
* *
* *
* *
* *
* Complete C# Program
Fixed rows = 5 version:
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
int i, j, k;
int rows = 5;
for (i = rows; i >= 1; i--)
{
for (j = rows; j >= 1; j--)
{
if (i == j)
Console.Write("*");
else
Console.Write(" ");
}
for (k = 2; k <= rows; k++)
{
if (i == k)
Console.Write("*");
else
Console.Write(" ");
}
Console.WriteLine();
}
}
}
}🧠 How It Works
Setup
rows, i, j, k match the hollow-V pattern: two inner loops per row, each cell is Console.Write("*") or Console.Write(" ") from an if (i == j) / if (i == k) test.
Outer loop (reverse rows)
for (i = rows; i >= 1; i--) prints the widest pair of legs first. The last row (i == 1) only gets a star from the j loop—the k loop starts at 2, so the bottom is a single apex star with leading spaces.
Left leg: j from rows down to 1
for (j = rows; j >= 1; j--) with if (i == j) places the left diagonal. As i counts down, the star in this block moves leftward row by row.
Right leg: k from 2 to rows
for (k = 2; k <= rows; k++) mirrors the left leg. When i > 1, you print a second * on that row; when i == 1, this loop never emits a star.
Finish the line
Console.WriteLine() ends each row. Line width is still 2 * rows - 1, same geometry as the upward hollow V, only the row order is reversed.
Hollow V
Vertex at the bottom, opening upward. O(n²) output for n = rows, O(1) extra space. Wide rows use horizontal scroll in the green preview on small screens.
Variation — User Input Version
Read rows with Console.ReadLine():
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
int rows;
int i, j, k;
Console.Write("Enter the number of rows: ");
rows = Convert.ToInt32(Console.ReadLine());
for (i = rows; i >= 1; i--)
{
for (j = rows; j >= 1; j--)
{
if (i == j)
Console.Write("*");
else
Console.Write(" ");
}
for (k = 2; k <= rows; k++)
{
if (i == k)
Console.Write("*");
else
Console.Write(" ");
}
Console.WriteLine();
}
}
}
}💡 Tips for Enhancement
Try These
- Switch the outer loop to
1..rowsto recover Program 7 - Validate
rows >= 1after parsing - Stack Program 7 then Program 8 to visualize a full hollow diamond
- Print row index
iwhere stars appear
Avoid
- Claiming two stars on the bottom row from both loops—only
jhitsi == 1 - Incrementing
iin the outer loop (that produces Program 7, not this shape) - Omitting spaces so columns no longer align
Key Takeaways
Same inner logic as Program 7; only outer loop direction changes.
Top row (i == rows): stars at j == rows and k == rows.
Bottom row (i == 1): one star from j; k loop is all spaces.
Line width remains 2 * rows - 1 characters.
Time complexity O(n²) for n rows.
❓ Frequently Asked Questions
i values run first, so the row with two outer stars (i == rows) is printed before smaller i values pull the legs inward.for (i = 1; i <= rows; i++). Program 8 uses for (i = rows; i >= 1; i--). The j and k loops and the if conditions are the same.i == 1, the right loop only considers k >= 2, so i == k never holds. The apex is the lone * from j == 1, plus padding spaces to the right.n rows, same as Program 7.Explore More C# Star Patterns!
Pair inverted-V and V-shaped halves to build diamonds and hourglass shapes.
This is the same trick as Program 6 versus Program 5: reverse the outer row index while keeping the per-row formulas unchanged.
12 people found this page helpful
