Well, if dealing with 2-d is your problem, try this. len n = r * c of the matrix.
use buble sorting, on matrix[0][0] to matrix[0][n-1]. It will sort, the matrix, left to right & top to bottom
And also, in the code, you use, NO_OF_ROWS as a matrix, as a function & as an integer. What is this?