| 2 | // even fibonacci numbers from Project Euler |
| 3 | |
| 4 | int 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 |
nothing calls this directly
no outgoing calls
no test coverage detected