CJCoding With Joseph
15free / daySign inCreate account

Heap Matrix Product with Full Cleanup

Multiply 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 — print one after the last line.

Hints4 available
Topics:
Pointers
📥 Auto-Input:
2 3 2\n1 2 3\n4 5 6\n7 8\n9 10\n11 12\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (p, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.