Write a Python Program to Display Fibonacci Sequence Using Recursion.

Write a Python Program to Display Fibonacci Sequence Using Recursion.

Fibonacci sequence:

The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1. In mathematical terms, it is defined by the recurrence relation ( F(n) = F(n-1) + F(n-2) ), with initial conditions ( F(0) = 0 ) and ( F(1) = 1 ). The sequence begins: 0, 1, 1, 2, 3, 5, 8, 13, 21, and so on. The Fibonacci sequence has widespread applications in mathematics, computer science, nature, and art.

Program
def recur_fibo(n):
    if(n<=1):
        return n
    else:
        return (recur_fibo(n-1)+recur_fibo(n-2))
    
if __name__=="__main__":
    nterms=int(input("Enter the number of terms (greater than 0): "))
    if(nterms<=0):
        print("Plese enter a positive integer")
    else:
        print("Fibonacci sequence:")
        for i in range(nterms):
            print(recur_fibo(i))



Output:

Enter the number of terms (greater than 0): 8
Fibonacci sequence:
0
1
1
2
3
5
8
13



More Questions


79 . Write a Python Program to Display Fibonacci Sequence Using Recursion.
80 . Write a Python Program to Find Factorial of Number Using Recursion.
81 . Write a Python Program to calculate your Body Mass Index.
82 . Write a Python Program to calculate the natural logarithm of any number.
83 . Write a Python Program for cube sum of first n natural numbers?
84 . Write a Python Program to find sum of array.



For latest job updates join Telegram Channel: https://t.me/sateeshm