Program#2: Matrix Multiplication (Done in the C language) I\'m having a lot of t
ID: 3728439 • Letter: P
Question
Program#2: Matrix Multiplication (Done in the C language)
I'm having a lot of trouble wrapping my head around how to do this.
I need to write a program that takes 2 command line arguments that are filenames. The first row of each file will be the number of rows & columns of the table of numbers to follow. Then the remaining lines of each file will contain the numbers of a matrix with that many rows and column. The maximum possible size of each matrix will be 10x10. The number of rows & columns can be different. The program will calculate the matrix multiplication of the two matrices, producing a third matrix -- but only if the number of rows of the first matrix equals the number of columns of the second matrix. Then your program will display all three matrices.
For maximum credit I need to implement at least one useful function.But I really don't care for that
For a Bonus:
I need to implement and properly use a readMatrix function that takes four parameters: a filename, and 3 "by reference" parameters (2D Array (int matrix[maxSize][maxSize]), and 2 pointers to integers: rows and columns) so that it can return the matrix and the size (rows/column) of the matrix.
Explanation / Answer
/** * C program to multiply two matrix using pointers */ #include #define ROW 10 #define COL 10 /* Function declarations */ void matrixInput(int mat[][COL]); void matrixPrint(int mat[][COL]); void matrixMultiply(int mat1[][COL], int mat2[][COL], int res[][COL]); int main() { int mat1[ROW][COL]; int mat2[ROW][COL]; int product[ROW][COL]; /* * Input elements in matrices. */ printf("Enter elements in first matrix of size %dx%d ", ROW, COL); matrixInput(mat1); printf("Enter elements in second matrix of size %dx%d ", ROW, COL); matrixInput(mat2); // Call function to multiply both matrices matrixMultiply(mat1, mat2, product); // Print product of both matrix printf("Product of both matrices is : "); matrixPrint(product); return 0; } /** * Function to input elements in matrix from user. * * @mat Two-dimensional array to store user input. */ void matrixInput(int mat[][COL]) { int row, col; for (row = 0; rowRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.