Find a Square Matrix such that sum of elements in every row and column is K | Function to print the required matrix ; Print k for the left diagonal elements ; Prvar 0 for the rest ; Driver code
function printMatrix ( n , k ) { for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { if ( i == j ) document . write ( k + " " ) ; else document . write ( " " ) ; } document . write ( " " ) ; } } var n = 3 , k = 7 ; printMatrix ( n , k ) ;