Sep 11, 2010 at 9:31am
Hi . how can compute the sum of integer number in an array with recursive function.
Sep 11, 2010 at 10:28am
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
Sep 11, 2010 at 10:30am
array[size] /*...*/
This will go out of bounds of your array.
Sep 11, 2010 at 1:24pm
Also, remove the semicolon after the 'else' keyword.
Sep 11, 2010 at 3:32pm
Try to avoid the stack overflow.