Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please write a program that reads two matrices and determines their product matr

ID: 673294 • Letter: P

Question

please write a program that reads two matrices and determines their product matrix.

Example :

M1 =
1 2 3

3 2 1

M2 =

1 2 3 4 5

2 5 3 1 4

5 4 3 2 1

  
equals to:   

P =

20 24 18 12 16
12 20 18 16 24

These are the requirements:

Implement the following functions:

Please use only the following functions:

float *allocate(int rows, int cols);
void readm(float *matrix, int rows, int cols);
void writem(float *matrix, int rows, int cols);
void mulmatrix(float *matrix1, int rows1, int cols1, float *matrix2, int cols2, float *product);

Input the row size and column size for matrix M1 and M2

Input the matrix

Validate the product matrix dimension

Validate the memory allocation

Please use this for the multiplication function:

void mulmatrix(float *matrix1, int rows1, int cols1, float *matrix2, int cols2, float *product)
{int i, j, k;
      for (i = 0; ________________ )
             for(j=0;________________ )
            {
                 for(k = 0, *product = 0;________________________)
/* p[i,j] += m1[i,k] * m2[k j]*/
            *product += matrix1[_____________] * matrix2[_________________];
     product++;
}
}

Explanation / Answer

#include void take_data(int a[][10], int b[][10], int r1,int c1, int r2, int c2); void multiplication(int a[][10],int b[][10],int mult[][10],int r1,int c1,int r2,int c2); void display(int mult[][10], int r1, int c2); int main() { int a[10][10], b[10][10], mult[10][10], r1, c1, r2, c2, i, j, k; printf("Enter rows and column for first matrix: "); scanf("%d%d", &r1, &c1); printf("Enter rows and column for second matrix: "); scanf("%d%d",&r2, &c2); /* If colum of first matrix in not equal to row of second matrix, asking user to enter the size of matrix again. */ while (c1!=r2) { printf("Error! column of first matrix not equal to row of second. "); printf("Enter rows and column for first matrix: "); scanf("%d%d", &r1, &c1); printf("Enter rows and column for second matrix: "); scanf("%d%d",&r2, &c2); } take_data(a,b,r1,c1,r2,c2); /* Function to take matices data */ multiplication(a,b,mult,r1,c1,r2,c2); /* Function to multiply two matrices. */ display(mult,r1,c2); /* Function to display resultant matrix after multiplication. */ return 0; } void take_data(int a[][10], int b[][10], int r1,int c1, int r2, int c2) { int i,j; printf(" Enter elements of matrix 1: "); for(i=0; i