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 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):

Output
*       *
 *     * 
  *   *  
   * *   
    *    
1

Complete C# Program

Fixed rows = 5 version:

C#
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

1

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.

Setup
2

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.

Order
3

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.

Left leg
4

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.

Right leg
5

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.

Line break
=

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.

2

Variation — User Input Version

Read rows with Console.ReadLine():

C#
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..rows to recover Program 7
  • Validate rows >= 1 after parsing
  • Stack Program 7 then Program 8 to visualize a 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, not this shape)
  • Omitting spaces so columns no longer align

Key Takeaways

1

Same inner logic as Program 7; only outer loop direction changes.

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++). Program 8 uses for (i = rows; i >= 1; i--). 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 apex 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 and V-shaped halves to build diamonds and hourglass shapes.

All C# 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