Even Fibonacci Sum

The Fibonacci series is a sequence of numbers in which each number is the sum of the two previous numbers, starting with 1 and 1.

Example: 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , . . . 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Assuming the values in the sequence don't exceed four million, what is the sum of the even terms?


The answer is 4613732.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Eric Taylor
Jun 18, 2017
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
var previous = 1; // First / Previous value in series
var current = 1; // Second / Current value in series
var next = 0; // Third / Next value in series
var evenSum = 0; // Sum of even numbers in series

while(current < 4000000){
  next = previous + current;

 if(current % 2 == 0) // If current value is even
  evenSum += current;

 previous = current; // "Shift" the values over
 current = next;
}

console.log(evenSum); // Output: 4613732

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...