find the subarray with given sum code example
Example: 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 ;
}