Utility function to print matrix
function printMatrix ( matrix , n ) { for ( let i = 0 ; i < n ; ++ i ) { for ( let j = 0 ; j < n ; ++ j ) document . write ( matrix [ i ] [ j ] + " " ) ; document . write ( " " ) ; } }