Input  : Number of Rows

Output:

1
121
12321
1234321
123454321

Code

 

        public static void PrintNumberPattern2(int rows)
        {
            int i, j, k;
            //Loop for number of Rows
            for (i = 1; i <= rows; i++)
            {
                // Loop for printing numbers in increasing order
                for (j = 1; j < 2 * i + 1; j++)
                {
                    Console.Write(j);
                    if (j >= i)
                    {
                        break;
                    }
                }
                // Loop for printing numbers in decreasing order
                for (k = j - 1; k > 0; k--)
                {
                    Console.Write(k);
                }
                Console.WriteLine("");
            }
        }