Project Euler Homework

002.cpp

Go to the documentation of this file.
00001 
00009 #include <iostream>
00010 using namespace std;
00011 int
00012 main ()
00013 {
00014 
00015   unsigned a = 1;
00016   unsigned b = 1;
00017   unsigned c = a + b;
00018   unsigned sum = 0;
00019 
00020   while (c <= 4e6)
00021     {
00022       if (c % 2 == 0)
00023         sum += c;
00024       a = b;
00025       b = c;
00026       c = a + b;
00027     }
00028 
00029   cout << sum << endl;
00030   return 0;
00031 }
00032 
 All Classes Files Functions Variables