Project Euler #2: Even Fibonacci numbers

  • + 0 comments
    long sum = 0;
            long x1 = 1, x2 = 2;
            while (x2 <= n) {
                if (x2 % 2 == 0)
                    sum += x2; 
                long next = x1 + x2; 
                x1 = x2;         
                x2 = next;
            }
            printf("%ld\n",sum);