Computing the cost for creating a perfect square (with N = 3)
Since the function is hardwired to 3x3 matrices, it would make sense to pass a 3x3 matrix as an argument:

int formingMagicSquare(const int s[3][3])


This way you will not worry about what to do if s_rows != 3.
stdlib provides int abs(int).
The line

    if(cost4_this_operation &lt; cost)cost = cost4_this_operation;


better be split into

    if(cost4_this_operation &lt; cost) {
        cost = cost4_this_operation;
    }


Even better, make a static inline int min(int, int) function.
I see nothing wrong with the loops.
Of course, the solution is not scalable for larger dimensions.