Row-Major Matrix in One malloc Block
mediumQuestion 461Store the whole matrix in a SINGLE block of rows * cols ints and index it row-major (block[r * cols + c]).
Input: the first line has two integers rows and cols. The remaining numbers are the rows * cols matrix values in row-major order (row 0 first, left to right).
Allocate ONE block with malloc, read every value into it, print the matrix back one row per line with values separated by a single space and no trailing space, then print the sum of each column on a final line in the exact form Col sums: a b c.
For the input:
2 3 1 2 3 4 5 6
the output is exactly what is shown in Expected Output.
Each line ends with a newline. Do not allocate a second array.
Free the memory you allocate before the program ends — this question checks for memory leaks.
Expected output
1 2 3 4 5 6 Col sums: 5 7 9
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...