using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[,] a = new int[3, 3] { { 1, 8, 5 }, { 6, 7, 1 }, { 8, 7, 6 } };
int[,] b = new int[3, 3] { { 4, 8, 1 }, { 6, 5, 3 }, { 4, 6, 5 } };
int[,] c = new int[a.GetLength(0), b.GetLength(1)];
Print(a);
Console.WriteLine();
Print(b);
Console.WriteLine();
// c[0, 0] = (a[0, 0] * b[0, 0]) + (a[0, 1] * b[1, 0]) + (a[0, 2] * b[2, 0])
for (int i = 0; i < a.GetLength(0); i++)
for (int j = 0; j < a.GetLength(1); j++)
c[i, j] = Calc(a, b, i, j);
Print(c);
}
static void Print(int[,] arr2d)
{
for (int i = 0; i < arr2d.GetLength(0); i++)
{
for (int j = 0; j < arr2d.GetLength(1); j++)
Console.Write("{0,4}", arr2d[i, j]);
Console.WriteLine();
}
}
static int Calc(int[,] a, int[,] b, int i, int j)
{
int sum = 0;
for (int x = 0; x < a.GetLength(0); x++)
sum += a[i, x] * b[x, j];
// Console.Write("a[{0}][{1}] * b[{2}][{3}] + ", i, x, x, j);
return sum;
}
}
}
/*
run:
1 8 5
6 7 1
8 7 6
4 8 1
6 5 3
4 6 5
72 78 50
70 89 32
98 135 59
*/