Using Normal Functions Fibonacci Series
Using Recursion Fibonacci Series
Advance Using Array
Using Normal Functions Fibonacci Series
#Using Normal Function for nth Fibonacci number
def fibo(n):
a = 0
b = 1
if n < 0:
print("Incorrect input")
elif n == 0:
return a
elif n == 1:
return b
else:
for i in range(2,n):
c = a + b
a = b
b = c
return b
print(fibo(19))
Using Recursion Fibonacci Series
#Using Recursion Function for nth Fibonacci number
def Fibo(n):
if n<0:
print("Incorrect input")
elif n==1:
return 0
elif n==2:
return 1
else:
return Fibo(n-1)+Fibo(n-2)
print(Fibo(9))
Advance Using Array
#( Using Arrays ): creating an array in the function to find the nth number in the Fibonacci series. [0,1,1,…]
|