Write a program that reads two matrices and determines their product matrix. For
ID: 3573121 • Letter: W
Question
Write a program that reads two matrices and determines their product matrix. For example: 1 2 3 1 2 3 4 5 M1 = and M2= 2 5 3 1 4 3 2 1 5 4 3 2 1 then 20 24 18 12 16 P = 12 20 18 16 24 Requirements: Implement the following functions: void readm(matrix [ ] [ ], int rows, int cols); void writem(matrix[ ][ ], int rows, int cols); void mulmatrix(float matrix1 [ ] [ ], int rows1, int cols1, 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 Hint: 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]*/
Explanation / Answer
Hi, Please find my implementation of all required functions.
Please let me know in case of any issue.
void readm(float matrix[][], int rows, int cols){
printf("Enter the elements of first matrix ");
for (int c = 0; c < rows; c++){
cout<<"Enter "<<cols<<" elements for row #"<<(c+1)<<": ";
for (int d = 0; d < cols; d++)
cin>>matrix[c][d];
}
}
void writem(float matrix[][], int rows, int cols){
for (int c = 0; c < rows; c++){
for (int d = 0; d < cols; d++){
cout<<matrix[c][d]<<" ";
}
cout<<endl;
}
}
void mulmatrix(float matrix1[][], int rows1, int cols1, float matrix2[][], int cols2, float product[][]){
int i, j, k;
for (i = 0; i < rows1; i++)
{
for (j = 0; j < cols2; j++)
{
product[i][j] = 0;
for (k = 0; k < cols1; k++)
product[i][j] += matrix1[i][k]*matrix2[k][j];
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.