Print a Number pattern

Write a program to print the below pattern

For example

Input:
5

Output:
0
505
45054
3450543
234505432
12345054321

Solution:


using System;

namespace NumberPattern
{
    class Program
    {
        public static void Main()
        {
            Console.WriteLine("Enter a number:");
            var row = Convert.ToInt32(Console.ReadLine());

            for (var i = 1; i <= row; i++)
            {
                var count = 0;
                int j;
                for (j = 1; j < row; j++)
                {
                    if (count >= i - 1) continue;
                    if (j < row - i + 1) continue;
                    Console.Write(j);
                    count++;
                }
                Console.Write("0");
                count = 0;
                for (--j; j >= 1; j--)
                {
                    if (count >= i - 1) continue;
                    Console.Write(j);
                    count++;
                }
                Console.WriteLine("");
            }
            Console.ReadLine();
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *