Heap Matrix Product with Full Cleanup
hardQuestion 475Multiply two matrices that you build yourself on the heap. No fixed-size arrays, no variable-length arrays - every matrix is an int ** (an array of row pointers, where each row is its own malloc).
Read from stdin, whitespace separated: - three integers n, m and p: matrix A is n x m and matrix B is m x p - then the n * m values of A, row by row - then the m * p values of B, row by row
Build A, B and the product C (n x p) on the heap. C[i][j] is the sum of A[i][k] * B[k][j] for k from 0 to m - 1.
Print C: one row per line, values separated by a single space, with a newline after every row. Print nothing else.
Sample input: 2 3 2 1 2 3 4 5 6 7 8 9 10 11 12
Free the memory you allocate before the program ends — this question checks for memory leaks: every row, then the array of row pointers.
Expected output
58 64 139 154
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...