Python program to calculate n-th term of Fibonacci series with the help to two approaches (there are many approaches to calculate n-th term).
Description:
- First Approach: Dynamic Programming
In this approach, we calculate all the terms of Fibonacci series up to n and if we need to calculate any other term which is smaller than n, then we don’t have to calculate it again.
- Second Approach: By Formula
In this approach we calculate the n-th term of Fibonacci series with the help of a formula.
Formula:
phi = ( 1 + sqrt(5) ) / 2
An = phin/ sqrt(5)
Example:
Input:
for n = 5
for n = 8
Output:
a5 = 5
a8 = 21
Python code to calculate n-th term of a Fibonacci series
Output
need an explanation for this answer? contact us directly to get an explanation for this answer