Monday, 8 July 2019

12th-Prog-02 Write a Python recursive code to compute the nth Fibonacci number.

#Write a Python recursive code to compute the nth Fibonacci number.:  video Click here

def fib(n1,n2,n):
    if n==0:
        return
    res=n1+n2
    print(res)
    fib(n2,res,n-1)
a=0
b=1
n=int(input("How many numbers to be printed: "))
print(a)
print(b)
fib(a,b,n-2)

Output
How many numbers to be printed: 5
0
1
1
2
3

1 comment: