Second rotation with respect to middle column
for ( int i = 0 ; i < N ; ++ i ) { for ( int j = 0 ; j < N / 2 ; ++ j ) { int temp = arr [ i ] [ j ] ; arr [ i ] [ j ] = arr [ i ] [ N - j - 1 ] ; arr [ i ] [ N - j - 1 ] = temp ; } } }