Hollow Diamond Star Pattern in C#

Beginner
⏱️ 9 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
2n − 1 rows total

What You'll Learn

This pattern is Program 7 (inverted hollow V, upper half) followed by the lower half using the same outer idea as Program 8: after i runs 1rows, run i from rows - 1 down to 1 with the same j and k inner loops and if (i == j) / if (i == k) tests.

Each printed line has width 2 * rows - 1 (for example 9 characters when rows = 5), including trailing spaces after the right star.

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

            /* Upper half: i = 1 .. rows */
            for (i = 1; i <= rows; 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();
            }

            /* Lower half: avoid duplicate widest row */
            for (i = rows - 1; 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

Upper half (i = 1rows)

for (i = 1; i <= rows; i++) runs the hollow widening V: each iteration prints one full row with the two inner loops below, then Console.WriteLine(). At i == rows you get stars at both outer columns of the waist.

Expanding
2

Lower half (i = rows - 11)

for (i = rows - 1; i >= 1; i--) repeats the same nested j / k bodies so the shape narrows again. Starting at rows - 1 avoids printing the widest row twice.

Mirrored
3

Console.Write on each cell

for (j = rows; j >= 1; j--): if (i == j) Console.Write("*"); else Console.Write(" ");. Then for (k = 2; k <= rows; k++) with the same if / else. When i == 1, only the j loop draws the top and bottom apex stars.

Diagonals
4

New line and width

After both inner loops, Console.WriteLine() ends the row. Every line has fixed width rows + (rows - 1) = 2 * rows - 1 (including interior spaces).

Line break
=

Full hollow diamond

Line count: rows + (rows - 1) = 2 * rows - 1. Each line does Θ(rows) writes → O(n²) for n = rows, O(1) extra space. Width 2n - 1 scrolls horizontally in the green preview on narrow 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 = 1; i <= rows; 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();
            }

            for (i = rows - 1; 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

  • Validate rows >= 1 after parsing
  • Replace * with #, digits, or custom symbols
  • Print only the first outer loop for an inverted hollow V (Program 7)
  • For a filled diamond, you need rules for the interior (for example distance from the vertical center), not only i == j and i == k
  • Use int.TryParse for safer input

Avoid

  • Starting the second outer loop at i == rows—you would duplicate the widest row
  • Claiming i != j && i != k alone builds a filled diamond (it does not; it inverts the hollow logic incorrectly)
  • Dropping trailing spaces so columns no longer align to width 2 * rows - 1

Key Takeaways

1

Upper half = Program 7; lower half = same inners with i counting down from rows - 1.

2

Widest row appears once, when i == rows in the first loop.

3

Each row: left edge via j, right edge via k; same tests on both halves.

4

Line width is always 2 * rows - 1 characters.

5

Time complexity O(n²) for n = rows.

❓ Frequently Asked Questions

The first outer loop grows i from 1 to rows. The second runs i from rows - 1 to 1, mirroring that shape. Both use the same j / k loops and diagonal conditions.
The widest line is already printed when i == rows in the first loop. Starting the second loop at rows - 1 prevents printing that line twice.
Yes, if you compute an effective row index or branch on upper vs lower half. Two loops are usually clearer and map directly to Programs 7 and 8.
O(n²) for n rows: about 2n - 1 lines, each with two inner passes of length Θ(n).

Explore More C# Star Patterns!

Programs 7 and 8 are the two halves of this diamond—practice them separately, then combine.

All C# Star Patterns →
Did you know?

The hollow diamond is a direct composition: Program 7’s loop plus Program 8’s loop with the duplicate middle row removed by starting the second phase at rows - 1.

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