Find trace of matrix formed by adding Row | Return sum of first n integers of an AP ; Return the trace of sum of row - major matrix and column - major matrix ; Finding nth element in AP in case of Row major matrix . ; Finding sum of first n integers of AP in case of Row major matrix ; Finding nth element in AP in case of Row major matrix ; Finding sum of first n integers of AP in case of Column major matrix ; Driven Program
function sn ( n , an ) { return ( n * ( 1 + an ) ) / 2 ; } function trace ( n , m ) { let an = 1 + ( n - 1 ) * ( m + 1 ) ; let rowmajorSum = sn ( n , an ) ; an = 1 + ( n - 1 ) * ( n + 1 ) ; let colmajorSum = sn ( n , an ) ; return rowmajorSum + colmajorSum ; } let N = 3 , M = 3 ; document . write ( trace ( N , M ) ) ;