Algorithm for multiplting two int[][]

From: bunallo (nmnm_at_alala.com)
Date: 02/28/05


Date: Mon, 28 Feb 2005 13:38:27 +0100

I am trying to make the product of two int[][] (matrices).

If I have the two matrices a and b I would like to calculate matrix c which
is the product of a and b:
In this example I use two matrices with length 2 that contains the same
numbers.

a: 1 2 b:1 2 = c: 7 10
   3 4 3 4 15 22

Here I create matrix a and matrix b:

    int[][] a = new int[2][2];
    int[][] b = new int[2][2];

    int fill = 1;
    for (int i = 0; i < 2; i++){
      for (int k = 0; k < 2; k++){
        a[i][k] = fill;
        b[i][k] = fill;
        fill++;
      }
    }

Here I try yo make the calculation:

    int result = 0;
    int result2 = 0;
    int[]store = new int[4]; // Where I store the values of the product
matrix x.

    for (int m = 0; m < 2; m++){
      for (int n = 0; n < 2; n++){
        result = result + (a[m][n] * b[n][m]);
      }
      result2 = result;
      store[m*m] = result2; // 7 and 22 get stored in my array.
      result = 0;
    }
  }
}

But I can only seem to calculate "7" and "22"! Does anybody have a hint for
how to get the other two result of c calculated??