Programming Pandit

c/c++/c#/Javav/Python


Latest Update

Tuesday, November 17, 2020

Python program to print fibonacci series using recursion. by G Krishna Chauhan

Source Code



def fibonacci(n): 

if n<=1: 

    return n 

else:

    return(fibonacci(n-1)+fibonacci(n-2))

num=int(input("How many terms you want to display: ")) 

for i in range(num): 

    print(fibonacci(i)," ", end=" ")




OUTPUT


How many terms you want to display: 9

0   1   1   2   3   5   8   13   21   

 

No comments:

Post a Comment