Question: can someone reformat the code below based on the below assignment? Assignment Matrix multiplication (matrixmul.c): Given an n x k matrix A and an k

can someone reformat the code below based on the below assignment?

Assignment

Matrix multiplication (matrixmul.c): Given an n x k matrix A and an k x m matrix B, with 1n,m,k300, write a C program that computes the matrix product C=AB. All entries in matrices A and B are integers with abolute value less than 1000, so you don't need to worry about overflow. If matrices A and B do not have the right dimensions to be multiplied, the product matrix C should have its number of rows and columns both set to zero. Input/Output: please use scanf and printf to handle the data input and output. Input format: Line 1: Two space-separated integers, n and k. Line 2 to n+1: line i+1 contains k space-separated integers: row i of matrix A. Line n+2: Two space-separated integers, k and m. Line n+3 to n+k+4: Line i+n+3 contains m space-separated integers: row i of matrix B. Sample Input:

3 2 1 1 1 2 -4 0 2 3 1 2 1 3 2 1 

Output format: Line 1: two space-separated n and m, the dimension of matrix C. Line 2 to m+1: Line i+1 contains m space-separated integers: row i of matrix C. Sample Output:

3 3 4 4 2 7 6 3 -4 -8 -4

code

#include

int main()

{

int m, n, p, q, c, d, k, sum = 0;

int first[10][10], second[10][10], multiply[10][10];

scanf("%d %d", &m, &n);

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

for (d = 0; d < n; d++)

scanf("%d", &first[c][d]);

scanf("%d %d", &p, &q);

if (n != p)

printf("The matrices can't be multiplied with each other. ");

else

{

for (c = 0; c < p; c++)

for (d = 0; d < q; d++)

scanf("%d", &second[c][d]);

for (c = 0; c < m; c++) {

for (d = 0; d < q; d++) {

for (k = 0; k < p; k++) {

sum = sum + first[c][k]*second[k][d];

}

multiply[c][d] = sum;

sum = 0;

}

}

printf("Product of the matrices: ");

printf("%d %d ",m,q);

for (c = 0; c < m; c++) {

for (d = 0; d < q; d++)

printf("%d ", multiply[c][d]);

printf(" ");

}

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!