Assign values at desired place in the matrix
for ( int i = 0 ; i < n - 1 ; i ++ ) { matrix [ i , u ] = i + 1 ; for ( int j = 1 ; j < n / 2 ; j ++ ) { int a = ( i + j ) % ( n - 1 ) ; int b = ( i - j + n - 1 ) % ( n - 1 ) ; if ( a < b ) { int temp = a ; a = b ; b = temp ; } matrix [ b , a ] = i + 1 ; } }