Write a function matrixmultiplication to multipy two matrice
Write a function matrix_multiplication() to multipy two matrices and put the result into a third matrix.
The function takes six arguments altogether, i.e. pointers to the matrices to be multiplied and the resulting matrix and three values for the number of rows, columns and the shared dimension. We want to assume that all values are of type integer. This said, the prototype of the function is:
matrix_multiplication(int* left_matrix, int* right_matrix, int* result_matrix, int rows, int cols, int shared);
Write a quick program that makes use of matrix_multiplication(). You are allowed to \"hard-code\" the values of the example matrices to be multiplied.
Solution
You can use this function for matrix multiplication
int **matrix_multiplication ( int **left_matrix, int **right_matrix,int **result,int m, int n, int p)
{
register int i=0, j=0, k=0;
for (i = 0; i < m; i++)
{
/* calloc initializes all to \'0\' */
result[i] = calloc (p, sizeof (**result));
// if (!result[i]) throw error
}
for (i = 0; i < m; i++)
{
for (j = 0; j < p; j++)
{
for (k = 0; k < n; k++)
{
result [i][j] += mtrx_a [i][k] * mtrx_b [k][j];
}
}
}
return result;
}
