Recursive Fibonacci Series (Using Number)

Objective

 To implement a recursive function that generates the Fibonacci series(using Numbers).

 

Theory

The Fibonacci series is a sequence of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1. Numbers that are part of the Fibonacci sequence are known as Fibonacci numbers.  

Mathematically, it is defined by the recurrence relation:  

                                    F(n)=F(n−1)+F(n−2) 

with initial conditions: 

                        F(0)=0, F(1)=1 

So, the Fibonacci series begins: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so on. 

 Applications of Fibonacci numbers include computer algorithms such as the Fibonacci search technique and the Fibonacci heap data structure, and graphs called Fibonacci cubes used for interconnecting parallel and distributed systems. They also appear in biological settings, such as branching in trees, the arrangement of leaves on a stem, the fruit sprouts of a pineapple, the flowering of an artichoke, and the arrangement of a pinecone's bracts. 

 

Learning Outcomes

  • Recursion: The code implements the Fibonacci sequence using recursion, which is a powerful programming technique that allows a function to call itself. By understanding this code, one can learn the basics of recursion, including how to write a function that calls itself and how to solve problems using recursion.
  • Input validation: The code checks whether the input nterms is a positive integer and prints an error message if it is not. By understanding this code, one can learn how to check for input validity and handle user input errors.
  • Looping: The code uses a for loop to iterate through a sequence of numbers and call the recur_fibo() function to generate each number in the Fibonacci sequence. By understanding this code, one can learn how to use loops to iterate through a sequence of data and perform operations on each item in the sequence.
  • Problem-solving skills: The Fibonacci sequence is a classic example of a problem that can be solved using recursion. By understanding this code, one can develop problem-solving skills and improve algorithmic thinking.