23. sum of matrix

 using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace additionoftwomatrixexample

{

    class Program

    {

        static void Main(string[] args)

        {

            int row, col;

            int [,]a=new int[5,5];

            int[,] b = new int[5, 5];

            int[,] c = new int[5, 5];

            Console.Write("Enter Number of Row:");

            row = Convert.ToInt16(Console.ReadLine());

            Console.Write("Enter Number of Column:");

            col = Convert.ToInt16(Console.ReadLine());


            //Get Value For First Matrix i.e a[]


            for (int i = 0; i < row; i++)

            {

                for (int j = 0; j < col; j++)

                {

                    Console.Write("Enter a[{0}][{1}]:", i, j);

                    a[i, j] = Convert.ToInt16(Console.ReadLine());

                }

            }


            // Print the First Matrix i.e. a[]

           

            Console.WriteLine("First Matrix");

          

            for (int i = 0; i < row; i++)

            {

                for (int j = 0; j < col; j++)

                {

                    Console.Write(a[i, j]+" ");

                }

                Console.WriteLine();

            }


            //Get Value For Second Matrix i.e b[]


            for (int i = 0; i < row; i++)

            {

                for (int j = 0; j < col; j++)

                {

                    Console.Write("Enter b[{0}][{1}]:", i, j);

                    b[i, j] = Convert.ToInt16(Console.ReadLine());

                }

            }


            // Print the Second Matrix i.e. b[]

           

            Console.WriteLine("Second Matrix");

           

            for (int i = 0; i < row; i++)

            {

                for (int j = 0; j < col; j++)

                {

                    Console.Write(b[i, j]+" ");

                }

                Console.WriteLine();

            }


            // Perform Addition Logic Here


            for (int i = 0; i < row; i++)

            {

                for (int j = 0; j < col; j++)

                {

                    c[i, j] = a[i, j] + b[i, j];

                }

            }

            Console.WriteLine();

            //Print The Addition Matrix i.e c[]


            Console.WriteLine("Addition Matrix");

            

            for (int i = 0; i < row; i++)

            {

                for (int j = 0; j < col; j++)

                {

                    Console.Write(c[i, j]+" ");

                }

                Console.WriteLine();

            }

            Console.Read();

        }

    }

}

OUTPUT:

Enter Number of Row:2

Enter Number of Column:2

Enter a[0][0]:1

Enter a[0][1]:2

Enter a[1][0]:3

Enter a[1][1]:4

First Matrix

1 2

3 4

Enter b[0][0]:1

Enter b[0][1]:2

Enter b[1][0]:3

Enter b[1][1]:4

Second Matrix

1 2

3 4


Addition Matrix

2 4

6 8


Comments

Popular posts from this blog

Quetion 6 : Consider the "in-order-issue/in-order-completion" execution sequence shown in f In Figure Decode OWE Execute 12 12 12 14 16 13 16 13 15 15 16 Write 024/06/02 11 3 4 11 12 13 13 N 15 16 a. Identify the most likely reason why I could not enter the execute fourth cycle. stage until the [2] b. Will "in-order issue/out-of-order completion" or "out-of-order issue/out-of-order completion" fix this? If so, which? Explain

Question 5:

7.Write a program to read a list containing item name, item code and cost interactively and produce a three-column output as shown below. NAME CODE COST Turbo C++ 1001 250.95 C Primer 905 95.70 ------------- ------- ---------- ------------- ------- ---------- Note that the name and code are left-justified and the cost is right-justified with a precision of two digits. Trailing zeros are shown.