JavaScript Program to Sum of Fibonacci Numbers at Even Indexes up to N Terms Last Updated : 19 Feb, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 IterationThe basic method is to use a loop to generate Fibonacci numbers up to N terms and sum the numbers at even indexes. JavaScript function sumEvenFibonacci(n) { if (n <= 0) return 0; let sum = 0; let a = 0, b = 1; for (let i = 1; i <= n; i++) { if (i % 2 === 0) { sum += b; } [a, b] = [b, a + b]; } return sum; } // Driver code const n = 10; console.log(`Sum of Fibonacci Numbers: ${sumEvenFibonacci(n)}`); OutputSum of Fibonacci Numbers: 88 Sum of Fibonacci Numbers at Even Indexes up to N Terms using RecursionWe 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. JavaScript function fibonacci(n) { if (n <= 1) return n; return fibonacci(n - 1) + fibonacci(n - 2); } function sumEvenFibonacci(n) { let sum = 0; for (let i = 2; i <= n; i += 2) { sum += fibonacci(i); } return sum; } // Driver code const n = 10; console.log(`Sum of Fibonacci Numbers: ${sumEvenFibonacci(n)}`); OutputSum of Fibonacci Numbers: 88 Sum of Fibonacci Numbers at Even Indexes up to N Terms using Dynamic ProgrammingTo optimize the recursive approach, we can use dynamic programming to store the Fibonacci numbers as we calculate them, reducing the number of calculations needed. JavaScript function sumEvenFibonacci(n) { if (n <= 0) return 0; let fib = [0, 1]; let sum = 0; for (let i = 2; i <= n; i++) { fib[i] = fib[i - 1] + fib[i - 2]; if (i % 2 === 0) { sum += fib[i]; } } return sum; } // Driver code const n = 10; console.log(`Sum of Fibonacci Numbers: ${sumEvenFibonacci(n)}`); OutputSum of Fibonacci Numbers: 88 Comment More infoAdvertise with us Next Article JavaScript Program to Sum of Fibonacci Numbers at Even Indexes up to N Terms V vkash8574 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Numbers JavaScript-Questions Similar Reads JavaScript Program to print Fibonacci Series The Fibonacci sequence is the integer sequence where the first two terms are 0 and 1. After that, the next term is defined as the sum of the previous two terms. The recurrence relation defines the sequence Fn of Fibonacci numbers:Fn = Fn-1 + Fn-2 with seed values F0 = 0 and F1 = 1Examples:Input : 5 4 min read How to calculate the Fibonacci series in JavaScript ? Fibonacci series is a number series that contains integers in the following pattern. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ..In terms of mathematics, the general formula for calculating the Fibonacci series is fn = fn-1 + fn-2 , where n ⥠2Here, f0 = 0 and f1 = 1. We need to calculate n Fibonacci num 4 min read R Program to Print the Fibonacci Sequence The Fibonacci sequence is a series of numbers in which each number (known as a Fibonacci number) is the sum of the two preceding ones. The sequence starts with 0 and 1, and then each subsequent number is the sum of the two previous numbers. The Fibonacci sequence has many applications in various fie 2 min read C Program to Find the Sum of Fibonacci Numbers at Even Indexes up to N Terms Here, we will build a C Program to Find the Sum of Fibonacci numbers at even indexes up to N termsFibonacci Numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, â¦â¦Input: N = 5Output:88 // Sum of the elements at even indexes = 0 + 1 + 3 + 8 + 21 + 55 = 88Approach:This approach includes solving the 2 min read JavaScript Program to Find n-th Fibonacci Number The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1. The sequence goes as follows: 0, 1, 1, 2, 3, 5, 8, 13, 21, and so on. Given an integer n, the task is to find the n-th Fibonacci number. These are the following met 2 min read Like