Sunday, May 15, 2011

Problem 2 (C++)

#include <iostream>
using namespace ::std;

int main()
{ 
        int a = 1;
        int b = 2;
        int c;
        int sum = 0;

        while(b < 4000000)
        {
                if(b%2 == 0)
                {
                        sum += b;
                }
                c = b;
                b += a;
                a = c;
        }

        cout << sum;
        cin >> sum;//pause
        return 0;
}

No comments:

Post a Comment