Not working for all cases

i wrote the entire code and i runned it…it is executing…but givining wrong anwser.
I used the case
3 *3 matrix
values are
1 2 3
4 5 6
7 8 9
it is row and column wise sorted…but the program giving the answer 24 which is wrong as all are positive number every added gives 45