Lines 32
Euler02 (5)
##### Permissions
Owner: msgordon
Group Owner: SnortSnort
Viewable by Everyone
Editable by msgordon
Siafoo is here to make coding less frustrating and to save you time.

# Euler02, C++ 1

 Language C++
# 's
` 1/**************************************** 2  Even Fibonacci numbers 3   Problem 2 4   Each new term in the Fibonacci sequence is generated by adding the previous 5two terms. By starting with 1 and 2, the first 10 terms will be: 6  1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... 7   8   By considering the terms in the Fibonacci sequence whose values do not 9exceed four million, find the sum of the even-valued terms.10****************************************/1112#include <iostream>13#include <cmath>1415using namespace std;1617/* Use Binet's formula to generate Fibonacci sequence.18   Only add to sum if number is even. */1920int main()21{22    /* Golden ratio */23    const double phi = (1.0 + sqrt(5.0))/2.0;24    const int max_term = 4000000;2526    int sum = 0;27    int a = 1;2829    for (int i = 0; a < max_term; i++)30    {31	/* (int) cast is like the floor function */32	a = (int) ((pow(phi,i)/sqrt(5.0))+1.0/2.0);3334	if (a % 2 == 0)35	    sum += a;36    }3738    cout << sum << endl;39    return 0;40}`