All,
I'm writing a recursive function to do the following:
//addbig( ) -- This function is sent an array of integers and the length of the array.
//It returns the sum of all integers in the array that are larger than 1000.
Somehow my function is not working. It is giving me zero as the output.
long addbig (const int arrInt[],int l)
{
if (l == 0)
return 0;
else if(arrInt[l]>1000)
return arrInt[l] + addbig (arrInt,l-1);
else
return addbig (arrInt,l-1);
}
My integer array is:
int arrInt[10]={1000,1,1000,2,1000,3,1000,4,1000,5};
Could anybody shed some light as to why this is not working, and help me a bit. haha no pun intended
las both the index of the element you are trying to look at and the number of elements left to look at. As the code is written, you will never look atarrInt[0]arrInt[l]is not in range of the array