Top MNC interview question which will be very useful for beginners to crack the interview and for there future careers

test

Breaking

Post Top Ad

Your Ad Spot

Monday, December 28, 2020

Program for Fibonacci numbers using recursive functions

 Question:

Program for Fibonacci numbers using recursive functions

Explanation:

The Fibonacci numbers are the numbers in the following integer sequence.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ……..

For Example:

                        Number 7
                        Result:13
Program:

def Fibonacci(n): 
if n<0: 
print("Incorrect input") 
elif n==0: 
return 0 
elif n==1: 
return 1
else: 
return Fibonacci(n-1)+Fibonacci(n-2) 


print(Fibonacci(7)) 

                                                                ---------End---------

Post Top Ad

Your Ad Spot