I'm trying to multiply to n**x**n dynamic matrices and returning it's result. This is the code for it:
long long int** Multiply(long long int** m1, long long int **m2)
{
static long long int** output;
output= new long long int* [k];
for (int i=0; i<k; i++)
output[k]= new long long int [k];
long long int cellRes= 0;
for (int i=0; i<k; i++)
{
for (int f=0; f<k; f++)
{
for (int j=0; j<k; j++)
{
cellRes+= m1[i][j]*m2[j][f];
}
output[i][f]= cellRes;
cellRes=0;
}
}
return output;
}
It seems to do it well at returning the new matrix, but for some reason the program is crashing after executing Multiply()... Even if I create a new matrix, allocate it and then assign Multiply() to it, it crashes.
I can't figure out what I'm doing wrong. Any idea?