Write a recursive function named summer that takes two parameters – an array of doubles and the size of the array – and returns the sum of the values in the array. The size parameter does not have to be the actual size of the array. It will be at the top level, but at the lower recursive levels it can be the size of the sub-array being worked on at that level.
Expert Answer
#include <iostream>
#include <string>
using namespace std;
double sum(double [], int);
int main()
{
double a[]={1.1,2.2,3.3,4.4,5.5,6.6,7.7};
cout<<“Sum”<<sum(a,7);
return 0;
}
double sum(double a[], int n){
if (n == 0){
return a[n];
}
else
return a[n]+sum(a,n-1);
}
ans: Sum30.8