Advertisement
Guest User

Untitled

a guest
Jul 27th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main() {
  4.    
  5.     int n1      = 1;    // Number 1
  6.     int n2      = 1;    // Number 2
  7.     int temp    = 0;    // Temporary variable
  8.     int total   = 0;    // Sum of sequence
  9.  
  10.     // While the current number in the fibonacci sequence is less than 4000000, consider the value
  11.     while ((temp = n1 + n2) < 4000000) {
  12.         n1 = n2;
  13.         n2 = temp;
  14.  
  15.         // If even
  16.         if (n2 % 2 == 0) {
  17.             total += n2;
  18.         }
  19.     }
  20.  
  21.     std::cout << "TOTAL: " << total << std::endl;
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement