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

Monday, June 15, 2015

Enter the row: 5

              1

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


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

            Console.WriteLine("Enter the row number");
            int n = int.Parse(Console.ReadLine());
            bool flag = true;

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

                for (int space = n; space > row; space--)
                {
                    Console.Write(" ");
                }

                for (int coll = 0; coll < row * 2 - 1; coll++)
                {

                    Console.Write(temp);

                    if (temp != n && flag)
                    {

                        temp++;

                        if (temp == n)
                        {

                            flag = false;

                        }
                    }

                    else
                    {

                        temp--;

                        if (temp == 1)
                        {

                            flag = true;

                        }
                    }
                }

                Console.WriteLine();

            }

            Console.WriteLine();

            Console.ReadLine();

        }

    }

No comments: