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]);
}
}
}