C# Program of Multiplication in Matrix using 2D Arrays

I am Faisal Mukhtar, Software Engineer. May be this post is helpful for you. C Sharp is usually known as C#. This Language is basically the Programming Language which is mainly used for object orientation. this language was developed by Microsoft. i personally feel that many people face problem while writing such codes for particular program. So, that is the reason i decided to create C Sharp problem resolving  post for that type of people. Here is a main program where approximately every beginner stuck.

C# Program of Multiplication in Matrix using 2D Arrays

Question:


Make a program in which input values in 2×2 Matrix  and then again input values in 2×2 Matrix. Then, using multiplication method of Matrix, multiply both the matrices. and Show the Resultant Matrix. using Dense Array.

Code:
 {
            int[,] array1 = new int[,] { { 2, 5 }, { 9, 3 } };
            int[,] array2 = new int[,] { { 8, 6 }, { 7, 1 } };
            int[,] array3 = new int[2, 2];
            Console.WriteLine("\nFirst matrix Will be Given as: ");
            for(int i=0;i<2;i++)
            {
                for (int j = 0; j < 2;j++)
                {
                    Console.WriteLine(i+" "+ j+ " of 1st matrix is: " + array1[i,j]);
                }
             }
            Console.WriteLine("");
            Console.WriteLine("Second matrix Will be Given as: ");
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    Console.WriteLine(i + " " + j + " of 2st matrix is: " + array2[i, j]);
                }
            }
           for(int i=0;i<2;i++)
            {
                for (int j = 0; j < 2;j++)
                {
                    for(int k=0;k<2;k++)
                    {
                        array3[i, k] += array1[i, j] * array2[j, k];
                    }
                }
             }
            Console.WriteLine("\nThe Resultant Matrix Will Be: ");
            for (int i = 0; i < 2; i++)
            {
             
                    for (int k = 0; k < 2; k++)
                    {
                        Console.WriteLine(i + " " + k + " of Matrix Will be " + array3[i, k]);
                    }
             
            }
        }

Output:

C# Program of Multiplication in Matrix using 2D Arrays


Faisal Mukhtar

Assalam u Alaikum. I am web Developer, Web Application Developer, Web Designer, Free Lancer, Intro and outro maker, Logo Designer. If you like my work, so kindly give your feedbacks and intouch with me through my Social Links. Thank You