text: 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 ; Driver Code
code: < ? php function sn ( $ n , $ an ) { return ( $ n * ( 1 + $ an ) ) / 2 ; } function trace ( $ n , $ m ) { $ an = 1 + ( $ n - 1 ) * ( $ m + 1 ) ; $ rowmajorSum = sn ( $ n , $ an ) ; $ an = 1 + ( $ n - 1 ) * ( $ n + 1 ) ; $ colmajorSum = sn ( $ n , $ an ) ; return $ rowmajorSum + $ colmajorSum ; } $ N = 3 ; $ M = 3 ; echo trace ( $ N , $ M ) , " STRNEWLINE " ; ? >