Hi . how can compute the sum of integer number in an array with recursive function.
int array_sum(int array[], int size)
{
if (size == 0)
return 0;
else;
return array[size] + array_sum(array, size - 1);
}
int main()
{
int a[] = { 4, 2, 2 };
cout << array_sum(a, 3) << endl;
return 0;
}
i Have problem in sum
array[size] /*...*/
This will go out of bounds of your array.
Also, remove the semicolon after the 'else' keyword.
Try to avoid the stack overflow.