Write a program that reads two matrices and determines their product matrix. For
ID: 3931947 • Letter: W
Question
Write a program that reads two matrices and determines their product matrix. For example: M1 = 1 2 3 3 2 1 and M2 = 1 2 3 4 5 2 5 3 1 4 5 4 3 2 1 then P = 20 24 18 12 16 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 matrixl [] [], int rowsl, int colsl, matrix2 [] [], int cols2, float product [][]); Input the row size and column size for matrix M1 and M2 Input the matrix Validate the product matrix dimensionExplanation / Answer
include void readmatrix(int firstMatrix[][10], int secondMatrix[][10], int rowFirst, int columnFirst, int rowSecond, int columnSecond); void multiplyMatrices(int firstMatrix[][10], int secondMatrix[][10], int multResult[][10], int rowFirst, int columnFirst, int rowSecond, int columnSecond); void display(int mult[][10], int rowFirst, int columnSecond); int main() { int firstMatrix[10][10], secondMatrix[10][10], mult[10][10], rowFirst, columnFirst, rowSecond, columnSecond, i, j, k; printf("Enter rows and column for first matrix: "); scanf("%d %d", &rowFirst, &columnFirst); printf("Enter rows and column for second matrix: "); scanf("%d %d", &rowSecond, &columnSecond); // If colum of first matrix in not equal to row of second matrix, asking user to enter the size of matrix again. while (columnFirst != rowSecond) { printf("Error! column of first matrix not equal to row of second. "); printf("Enter rows and column for first matrix: "); scanf("%d%d", &rowFirst, &columnFirst); printf("Enter rows and column for second matrix: "); scanf("%d%d", &rowSecond, &columnSecond); } // Function to take matrices data readmatrix(firstMatrix, secondMatrix, rowFirst, columnFirst, rowSecond, columnSecond); // Function to multiply two matrices. multiplyMatrices(firstMatrix, secondMatrix, mult, rowFirst, columnFirst, rowSecond, columnSecond); // Function to display resultant matrix after multiplication. display(mult, rowFirst, columnSecond); return 0; } void readmatrix(int firstMatrix[][10], int secondMatrix[][10], int rowFirst, int columnFirst, int rowSecond, int columnSecond) { int i, j; printf(" Enter elements of matrix 1: "); for(i = 0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.