Exercise: Dynamic Matrix Function
In an earlier exercise, we saw how to print a matrix and how to multiply two matrices. But the size of the matrix was a fixed constant. Now, we want to accomplish the same using a matrix that’s created using dynamic memory allocation, so that the number of rows and columns of the matrix are passed as variables to a function createMatrix.
Question
Complete the definitions of the functions createMatrix, destroyMatrix, printMatrix, and matrixMult provided below.
First, your function will be called with two matrices. After that, the function will be applied to these matrices and the output will be printed. Here is an example of what the output from your finished program might look like:
Note: For the
printMatrixandmatrixMultfunctions, you may make minor modifications to the solution seen in the earlier exercise.
Exercise: Dynamic Matrix Function
In an earlier exercise, we saw how to print a matrix and how to multiply two matrices. But the size of the matrix was a fixed constant. Now, we want to accomplish the same using a matrix that’s created using dynamic memory allocation, so that the number of rows and columns of the matrix are passed as variables to a function createMatrix.
Question
Complete the definitions of the functions createMatrix, destroyMatrix, printMatrix, and matrixMult provided below.
First, your function will be called with two matrices. After that, the function will be applied to these matrices and the output will be printed. Here is an example of what the output from your finished program might look like:
Note: For the
printMatrixandmatrixMultfunctions, you may make minor modifications to the solution seen in the earlier exercise.