Answers for "Write a program to find the sum of all sub-arrays of a given integer array."

C++
1

Write a program to find the sum of all sub-arrays of a given integer array.

long int SubArraySum( int arr[] , int n ) 
{ 
    long int result = 0; 
  
    // computing sum of subarray using formula 
    for (int i=0; i<n; i++) 
        result += (arr[i] * (i+1) * (n-i)); 
  
    // return all subarray sum 
    return result ; 
}
Posted by: Guest on November-06-2020

Code answers related to "Write a program to find the sum of all sub-arrays of a given integer array."

Browse Popular Code Answers by Language