Wolfos

Project Euler problem 2

Feb 3rd, 2012
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main (int argc, const char * argv[])
  4. {
  5.     int fibone = 1;
  6.     int fibtwo = 2;
  7.     int temp;
  8.    int answer = 0;
  9.    
  10.     while(fibtwo<4000000){
  11.         temp = fibtwo;
  12.         fibtwo = fibone + fibtwo;
  13.         fibone = temp;
  14.         if(fibtwo%2==0){
  15.             answer +=fibtwo;
  16.         }
  17.     }
  18.  
  19.     // We add 2 because 2 isn't counted (it gets changed before it can be added)
  20.     std::cout << answer + 2;
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment