Sum of the updated array after performing the given operation | Utility function to return the sum of the array ; Function to return the sum of the modified array ; Find the sum of the subarray arr [ i + 1. . . n - 1 ] ; Subtract the subarray sum ; Return the sum of the modified array ; Driver code
function sumArr ( arr , n ) { var sum = 0 ; for ( i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; return sum ; } function sumModArr ( arr , n ) { for ( i = 0 ; i < n - 1 ; i ++ ) { var subSum = 0 ; for ( j = i + 1 ; j < n ; j ++ ) { subSum += arr [ j ] ; } arr [ i ] -= subSum ; } return sumArr ( arr , n ) ; } var arr = [ 40 , 25 , 12 , 10 ] ; var n = arr . length ; document . write ( sumModArr ( arr , n ) ) ;