VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascript-program-to-sum-of-fibonacci-numbers-at-even-indexes-up-to-n-terms/

⇱ JavaScript Program to Sum of Fibonacci Numbers at Even Indexes up to N Terms - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaScript Program to Sum of Fibonacci Numbers at Even Indexes up to N Terms

Last Updated : 19 Feb, 2024

Fibonacci numbers are a sequence of numbers where each number is the sum of the two preceding ones, starting from 0 and 1. In this article, we will explore how to calculate the sum of Fibonacci numbers at even indexes up to N terms using JavaScript.

Sum of Fibonacci Numbers at Even Indexes up to N Terms using Iteration

The basic method is to use a loop to generate Fibonacci numbers up to N terms and sum the numbers at even indexes.


Output
Sum of Fibonacci Numbers: 88

Sum of Fibonacci Numbers at Even Indexes up to N Terms using Recursion

We can also use recursion to calculate Fibonacci numbers and sum the even-indexed terms. However, this approach might be less efficient for larger values of N due to the overhead of recursive calls.


Output
Sum of Fibonacci Numbers: 88

Sum of Fibonacci Numbers at Even Indexes up to N Terms using Dynamic Programming

To optimize the recursive approach, we can use dynamic programming to store the Fibonacci numbers as we calculate them, reducing the number of calculations needed.


Output
Sum of Fibonacci Numbers: 88
Comment