Find the product of sum of two diagonals of a square Matrix | Function to find the product of the sum of diagonals . ; Initialize sums of diagonals ; Return the answer ; Driven code ; Function call
function product ( mat , n ) { let d1 = 0 , d2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { d1 += mat [ i ] [ i ] ; d2 += mat [ i ] [ n - i - 1 ] ; } return d1 * d2 ; } let mat = [ [ 5 , 8 , 1 ] , [ 5 , 10 , 3 ] , [ - 6 , 17 , - 9 ] ] ; let n = mat . length ; document . write ( product ( mat , n ) ) ;