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