Was watching this video By Anton Spraul : https://www.youtube.com/watch?v=oKndim5-G94&index=4&list=PLKQ5LYb497AZIZe9dBWy8GwLluVaMQVj0 wherein he talks about solving recursion by using an iterative function and a dispatcher function. I tried to find the nth fibonnaci number by using the same approach but the issue is that he uses the end values of an array in the dispatcher which are empty in my case. This is what i am trying to do:
//n is the nth fibonnaci number to be found.
int fibonacci(int fiboarray[], int number)
{
int i = 2;
for (i = 2; i < number; i++)
{
fiboarray[i] = fiboarray[i - 1] + fiboarray[i - 2];
}
return fiboarray[i - 1];
}
int fibonaccidispatcher(int fiboarray[], int number)
{
if(number==0)return 0;
int last=fiboarray[number-1]+fiboarray[number-2];
fiboarray[number]=fibonaccidispatcher(fiboarray,number-1)+last;
return fiboarray[number];
// return diff;
}
I know the iterative function works directly but what i am trying to do is to use the approach in the video to convert it into an recursive function.