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 );

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 F

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site