Function for matrix multiplication .
static void multiply ( int [ , ] mat , int [ , ] res ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { res [ i , j ] = 0 ; for ( int k = 0 ; k < N ; k ++ ) res [ i , j ] += mat [ i , k ] * mat [ k , j ] ; } } }