欧拉计划 第2题

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

 

int a = 1, b = 2;
long result = 2;
while (result < 4000000)
{
int c = a + b;
a
= b;
b
= c;
if (c % 2 == 0) result += c;
}
Console.WriteLine(result);

 

posted @ 2011-08-28 17:21  kiminozo  阅读(316)  评论(0编辑  收藏  举报