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

class Program
    {
        static void Main(string[] args)
        {
            int m, n, row, col;
            int d1 = 0, d2 = 0, x = 0, c = 0;

            Console.WriteLine("enter row :");
            m = int.Parse(Console.ReadLine());

            Console.WriteLine("enter col :");
            n = int.Parse(Console.ReadLine());

            int[,] arr = new int[m, n];//main matrix
            int[] arr2 = new int[m];//storing for col
            int[] arr3 = new int[n];//storing for row

            //taking array element from the user

            Console.WriteLine("enter array element:");

            for (int r1 = 0; r1 < m; r1++)
            {

                for (int c1 = 0; c1 < n; c1++)
                {

                    arr[r1, c1] = int.Parse(Console.ReadLine());

                }
            }

            //arry element as out put

            Console.WriteLine("array:");

            for (int i = 0; i < m; i++)
            {

                for (int j = 0; j < n; j++)
                {

                    Console.Write(arr[i, j]);

                    Console.Write("\t");

                }

                Console.WriteLine();

            }

            //main logic

            for (row = 0; row < m; row++)
            {

                for (col = 0; col < n; col++)
                {

                    if (row == col)

                        d1 = d1 + arr[row, col];

                    if (row + col == n - 1)

                        d2 = d2 + arr[row, col];

                    //x < m is used for store the col value into arr2 when a row is 0 other than this loop shud not execute

                    if (x < m)
                    {

                        for (int k = 0; k < m; k++)
                        {

                            arr2[col] = arr2[col] + arr[k, col];

                        }

                        x = x + 1;

                    }

                    arr3[row] = arr3[row] + arr[row, col];

                }

                Console.WriteLine();

            }

            Console.WriteLine("d1=" + d1);
            Console.WriteLine("d2=" + d2);

            if (d1 == d2)
            {

                for (int y = 0; y < m; y++)
                {

                    Console.WriteLine("row" + arr2[y]);
                    Console.WriteLine("col" + arr3[y]);

                    if (arr2[y] != d2 || arr3[y] != d2)
                    {

                        c = 1;
                        break;
                    }
                }

                if (c == 0)
                    Console.WriteLine("magic matrix:");
                else

                    Console.WriteLine("not magic matrix:");
            }

            Console.ReadLine();

        }


    }

OUTPUT:

No comments: