hi,
Why "Fibonacci (day-1)" and "Fibonacci (day-2)" are not the same recursive procedure?
Code is as follows:
#include
int Fibonacci(int day)
{
if(day==1||day==2)
return 1;
else
return Fibonacci(day-1)+Fibonacci(day-2);
}
void main()
{
printf("Fibonacci sequence:%d\n",Fibonacci(7));
}
thank.

VulpesPosted Sep 22, 2013, 5:59 AM
By the nature of the Fibonacci sequence:
fib(7) = fib(6) + fib(5)
where:
fib(6) = fib(5) + fib(4)
fib(5) = fib(4) + fib(3)
and so on.
The recursion will continue until you get to either fib(1) or fib(2), both of which are 1. The stack will then unwind and a result will be returned.
Ken HPosted Sep 22, 2013, 9:42 PM