We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Wednesday, June 10, 2015

  1 2 3 4 5 4 3 2 1
   1 2 3 4    4 3 2 1
   1 2 3          3 2 1
   1 2                2 1
   1                      1

   1 2                2 1
   1 2 3          3 2 1
   1 2 3 4    4 3 2 1
   1 2 3 4 5 4 3 2 1



 class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("Enter the no of lines");

            int n = int.Parse(Console.ReadLine());

            for (int row = n; row >= 1; row--)
            {

                for (int col = 1; col <= row; col++)
                {
                    Console.Write(col);
                }

                for (int space = 1; space <= ((n - row) * 2) - 1; space++)
                {
                    Console.Write(" ");
                }
                if (row == n)
                {
                    for (int col = n - 1; col >= 1; col--)
                    {
                        Console.Write(col);
                    }
                }
                else
                {
                    for (int col = row; col >= 1; col--)
                    {
                        Console.Write(col);
                    }

                }
                Console.WriteLine();
            }

            for (int row = 1; row <= n; row++)
            {

                for (int col = 1; col <= row; col++)
                {
                    Console.Write(col);
                }

                for (int space = 1; space <= (n - row) * 2 - 1; space++)
                {
                    Console.Write(" ");
                }

                if (row == n)
                {
                    for (int col = n - 1; col >= 1; col--)
                    {
                         Console.Write(col);
                    }
                }
                else
                {

                    for (int col = row; col >= 1; col--)
                    {
                        Console.Write(col);
                    }

                }

                Console.WriteLine();

            }

            Console.ReadLine();

        }
    }

No comments: