What vart says about using a printf to trace the calls is very important. Here's another tip: rather than doing this
Code:
if(start<size){
[your entire function here]
}else
return max;
Why not write:
Code:
if (start>=size) return max;
The execution is identical but the second version will save you a nest which makes the code more manageable.
ps. what you've got thus far is way too crazy. I just wrote this function in less than ten lines. Here's the prototype and the call:
Code:
int setlength (int *ray, int len, int index, int count, int high);
int main() {
int ray[]={0,4,12,2,3,4,5,7,9,10,14};
printf("answer=%d\n",setlength(ray,11,0,1,1));
return 0;
}
Output: answer=4
The function always returns
high.
count keeps track of the current number of numbers in a series. No loops, all recursion.