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

Enter the input: 5

1    2   3   4    5

16                  6
15                  7
14                  8
13 12 11 10   9

      class Program
 
    {

        static void Main(string[] args) 
        {

            Console.WriteLine("Enter a number");

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

            int temp = 4 * num - 4;

            int count = 1;

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

                for (int col = 1; col <= num; col++) 
                {

                    if (row == 1) 
                    {

                        Console.Write(count++ + "  ");

                    }

                    else if (col == num) 
                    {

                        Console.Write(count++ + " ");

                    } 
                    else if (col == 1) 
                    {

                        Console.Write(temp-- + " ");

                    }

                    else if (row == num) 
                    {

                        Console.Write(temp-- + " ");

                    } 
                    else 
                    {

                        Console.Write("  " + " ");

                    }

                }

                Console.WriteLine();

            }

            Console.ReadLine();

        } 

    }

No comments: