Concentric Number Diamond in C#

Beginner
⏱️ 7 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Nested Loops + Symmetry

What You’ll Learn

How to print a concentric number diamond where values decrease toward the center and then increase back out.

This is built by printing the top half (k down to 1) and then mirroring it for the bottom half (2 up to k).

⭐ Pattern Output

For k = 5, the pattern looks like this:

Output
5 5 5 5 5 5 5 5 5\n5 4 4 4 4 4 4 4 5\n5 4 3 3 3 3 3 4 5\n5 4 3 2 2 2 3 4 5\n5 4 3 2 1 2 3 4 5\n5 4 3 2 2 2 3 4 5\n5 4 3 3 3 3 3 4 5\n5 4 4 4 4 4 4 4 5\n5 5 5 5 5 5 5 5 5
1

Complete C# Program

Use two passes: the first prints rows from k down to 1, and the second prints rows from 2 up to k.

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, j;
            int k = 5;

            for (i = k; i >= 1; i--)
            {
                for (j = k; j >= 1; j--)
                    Console.Write((j > i ? j : i) + " ");

                for (j = 2; j <= k; j++)
                    Console.Write((j > i ? j : i) + " ");

                Console.WriteLine();
            }

            for (i = 2; i <= k; i++)
            {
                for (j = k; j >= 1; j--)
                    Console.Write((j > i ? j : i) + " ");

                for (j = 2; j <= k; j++)
                    Console.Write((j > i ? j : i) + " ");

                Console.WriteLine();
            }
        }
    }
}

🧠 How It Works

1

Pick the outer value \(k\)

int k = 5; decides the outermost number and the grid size.

Setup
2

Print the top half

for (i = k; i >= 1; i--) prints rows from k down to 1, shrinking toward the center.

Top half
3

Build a row (left + right)

Each row is printed in two parts: the left side counts k..1, and the right side mirrors with 2..k.

Symmetry
4

Choose the cell value

The rule (j > i ? j : i) prints the larger value so the border stays at k and values decrease toward the center.

Cell logic
5

Mirror the bottom half

for (i = 2; i <= k; i++) prints rows back from 2 up to k to complete the diamond.

Bottom half
=

Concentric number diamond

The output size is \(2k - 1\) by \(2k - 1\), so the time complexity is O(k²).

2

Variation — User Input k

Let the user choose the outer value \(k\).

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int k;
            Console.Write("Enter k: ");
            if (!int.TryParse(Console.ReadLine(), out k) || k <= 0)
            {
                Console.WriteLine("Please enter a positive integer.");
                return;
            }

            for (int i = k; i >= 1; i--)
            {
                for (int j = k; j >= 1; j--)
                    Console.Write((j > i ? j : i) + " ");
                for (int j = 2; j <= k; j++)
                    Console.Write((j > i ? j : i) + " ");
                Console.WriteLine();
            }

            for (int i = 2; i <= k; i++)
            {
                for (int j = k; j >= 1; j--)
                    Console.Write((j > i ? j : i) + " ");
                for (int j = 2; j <= k; j++)
                    Console.Write((j > i ? j : i) + " ");
                Console.WriteLine();
            }
        }
    }
}

💡 Tips for Enhancement

Try These

  • Print without spaces to make it a tight 9x9 grid
  • Change the filler (space after numbers) to a tab for wider separation
  • Set k to 7 or 9 to generate a larger concentric diamond
  • Replace numbers with characters to create alphabet concentric patterns

Avoid

  • Using a non-positive k (validate input when taking user values)
  • Forgetting the bottom half loop (the pattern won’t be symmetric)
  • Using inconsistent spacing per cell (alignment will break)

Key Takeaways

1

Width (and height) of the grid is \(2k - 1\).

2

Top half prints rows k..1, bottom half prints 2..k.

3

Each cell uses the same rule: print the larger of the row-layer and column-layer values.

4

Time complexity is O(k²) because the grid area is about \((2k-1)^2\).

❓ Frequently Asked Questions

Because k is the outer layer value. All border cells belong to the outermost layer, so they print k (5 in this example).
The center prints 1 because it’s the deepest layer of the concentric pattern.
Set k = 7. The size becomes 2k-1 = 13.
Yes. Replace Console.Write(value + " "); with Console.Write(value);. For double-digit values, consider fixed-width formatting.

Explore More C# Number Patterns!

Concentric patterns are excellent practice for symmetry, layers, and loop boundaries.

All Number Patterns →
Did you know?

Most concentric square/diamond patterns can be generated by computing a cell’s distance from the border and mapping that distance to a value.

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