Find the sum of elements of the Matrix generated by the given rules | Function to return the required sum ; To store the sum ; For every row ; Update the sum as A appears i number of times in the current row ; Update A for the next row ; Return the sum ; Driver code
function sum ( A , B , R ) { let sum = 0 ; for ( let i = 1 ; i <= R ; i ++ ) { sum = sum + ( i * A ) ; A = A + B ; } return sum ; } let A = 5 , B = 3 , R = 3 ; document . write ( sum ( A , B , R ) ) ;