Give a number N, print alternate fibonacci numbers till n-th Fibonacci.
Input : N = 7 Output : 0 1 3 8 Input : N = 15 Output : 0 1 3 8 21 55 144 377
Read method 2 in the following article : fibonacci number
Approach:Using dynamic programming approach. Keep storing the previously calculated fibonacci numbers and using the previous two to store the next fibonacci number.
0 1 3 8 21 55 144 377
Time Complexity : O(n)
Auxiliary Space : O(1)
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Sum of Fibonacci Numbers with alternate negatives
- Delete odd and even numbers at alternate step such that sum of remaining elements is minimized
- Sum of Fibonacci Numbers
- Non Fibonacci Numbers
- GCD and Fibonacci Numbers
- Even Fibonacci Numbers Sum
- The Magic of Fibonacci Numbers
- Sum of Fibonacci Numbers in a range
- Find the sum of first N odd Fibonacci numbers
- Sum of squares of Fibonacci numbers
- C Program for Fibonacci numbers
- Prime numbers and Fibonacci
- Program for Fibonacci numbers
- Remove all the fibonacci numbers from the given array
- Find two Fibonacci numbers whose sum can be represented as N
- Large Fibonacci Numbers in Java
- Find the GCD of N Fibonacci Numbers with given Indices
- Interesting facts about Fibonacci numbers
- Program to print first n Fibonacci Numbers | Set 1
- Sum of all Non-Fibonacci numbers in a range for Q queries
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.