MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

project_euler_problems/EvenFibonacciNumbers/solution.cpp:4–28  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2// even fibonacci numbers from Project Euler
3
4int main()
5{
6 int firstTerm {1};
7 int secondTerm {2};
8 int tempTerm {0};
9
10 long sum {0};
11
12 while (secondTerm <= 4000000){
13
14 // only count even fibonacci numbers toward our sum
15 if (secondTerm % 2 == 0)
16 sum += secondTerm;
17
18 // for the next loop, firstTerm is equal to the previous second
19 // and second is equal to the sum of the current two terms
20 tempTerm = secondTerm;
21 secondTerm += firstTerm;
22 firstTerm = tempTerm;
23 }
24
25 std::cout << "Sum of even fibonacci numbers <= 4 million: " << sum << std::endl;
26
27 return 0;
28}
29

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected