text: Construct a matrix with sum equal to the sum of diagonal elements | Function to construct matrix with diagonal sum equal to matrix sum ; If diagonal position ; Positive element ; Negative element ; Driver Code
code: function constructmatrix ( N ) { let check = true ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { if ( i == j ) { document . write ( " " ) ; } else if ( check ) { document . write ( " " ) ; check = false ; } else { document . write ( " " ) ; check = true ; } } document . write ( " " ) ; } } let N = 5 ; constructmatrix ( 5 ) ;