What is wrong with this simple recursive solution to get a F
What is wrong with this simple recursive solution to get a Fibonacci sequence number?
def Fib( n ):
if n < 0:
return 0
elif n <= 2:
return 1
else
return Fib( n - 1) + Fib( n - 2 )
Solution
In code:
So, After changes,Program will look like following;
Fib( n )
if (n == 0)
return 0;
else if (n == 1)
return 1;
else
return Fib( n - 1) + Fib( n - 2 );
