Mr. Umar while performing some operations comes to know that the image that he wants can be obtained by multiplying the original image with the pattern. Help Mr. Umar to get the resultant image by performing the matrix multiplication.
Note: Matric multiplication is possible only if the number of columns of the first matrix is the same as the number of rows of the second matrix.
Example:
Matrix A (M, N) and Matrix B(P,Q)
Then N and P should be the same to perform matrix multiplication otherwise its not possible
Matrix A(M,N) * Matrix B(P,Q)= Result(M,Q)
The resultant matrix will be in the order of M and Q
int multiply_matrix(double* a[], int m, int n, double* b[], int p, int q, double* c[]) {
if (n == p)
{
int i, j, k;
for (i = 0; i < m; i++)
for (j = 0; j < q; j++)
{
c[i][j] = 0;
for (k = 0; k < n; k++)
c[i][j] += a[i][k] + b[k][j];
}
return 1;
}
return 0;
}
Comments
Leave a comment