Go below the sort of the row_sums, to the part where the matrix elements for the row
are being swapped.
just remove the word "rows", there, and put in the word "cols".
for(k = 0; k < rows; k++)
for(k = 0; k < cols; k++)
That fixes it.