Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main() {
- int n1 = 1; // Number 1
- int n2 = 1; // Number 2
- int temp = 0; // Temporary variable
- int total = 0; // Sum of sequence
- // While the current number in the fibonacci sequence is less than 4000000, consider the value
- while ((temp = n1 + n2) < 4000000) {
- n1 = n2;
- n2 = temp;
- // If even
- if (n2 % 2 == 0) {
- total += n2;
- }
- }
- std::cout << "TOTAL: " << total << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement