Given two integers A and B which are the first two terms of the series and another integer N. The task is to find the Nth number using Fibonacci rule i.e. fib(i) = fib(i – 1) + fib(i – 2)
Input: A = 2, B = 3, N = 4
The series will be 2, 3, 5, 8, 13, 21, …
And the 4th element is 8.
Input: A = 5, B = 7, N = 10
Approach: Intilalize variable sum = 0 that stores sum of the previous two values. Now, run a loop from i = 2 to N and for each index update value of sum = A + B and A = B, B = sum. Then, finally return the sum which is the required Nth element.
Below is the implementation of the above approach:
- Sum of nth terms of Modified Fibonacci series made by every pair of two arrays
- Factorial of each element in Fibonacci series
- Python | Find fibonacci series upto n using lambda
- Find n terms of Fibonacci type series with given first two terms
- Find n-th element in a series with only 2 digits (4 and 7) allowed
- Find n-th element from Stern's Diatomic Series
- Find n-th element in a series with only 2 digits (4 and 7) allowed | Set 2 (log(n) method)
- K- Fibonacci series
- n'th multiple of a number in Fibonacci Series
- Find the maximum possible value of the minimum value of modified array
- Print Fibonacci Series in reverse order
- C/C++ Program for nth multiple of a number in Fibonacci Series
- Find the modified array after performing k operations of given type
- C++ Program to print Fibonacci Series using Class template
- Find the sum of first N odd Fibonacci numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.