#
__Matrix Multiplication__

__Matrix Multiplication__

*Write a C program to perform matrix multiplication. Assume only square matrices of the same dimension.*

*
*

__Input Format:__
The input consists of (2*(m*m)+1) integers. The first integer corresponds to m, the number of rows /

columns in the matrix . The next m*m integers correspond to the elements in the first matrix. The last m*m

elements correspond to the elements in the second matrix. The elements are read in rowwise order, first

row first, then second row and so on. Assume that the maximum value of m is 10.

__Output Format:__
Refer sample output for details.

__Sample Input 1:__
2

4 5

6 9

1 2

3 4

__Sample Output 1:__
19 28

33 48

__Solution:__**#include<stdio.h>**

**int main()**

{

int m, a[10][10], b[10][10], mul[10][10], i, j, k, sum = 0;

scanf("%d", &m);

for(i = 0; i < m; i++)

{

for(j = 0; j < m; j++)

{

scanf("%d", &a[i][j]);

}

}

for(i = 0; i < m; i++)

{

for(j = 0; j < m; j++)

{

scanf("%d", &b[i][j]);

}

}

for(i = 0; i < m; i++)

{

for(j = 0; j < m; j++)

{

for(k = 0; k < m; k++)

{

sum = sum + a[i][k] * b[k][j];

}

mul[i][j] = sum;

sum = 0;

}

}

for(i = 0; i < m; i++)

{

for(j = 0; j < m; j++)

{

printf("%d ", mul[i][j]);

}

printf("\n");

}

return 0;

}

## No comments:

## Post a Comment

Your Comments here.