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);

 

相关文章:

  • 2022-02-15
  • 2022-01-13
  • 2021-08-14
  • 2022-01-02
  • 2021-04-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-11
  • 2022-01-29
  • 2022-02-14
  • 2021-10-03
  • 2021-08-08
  • 2021-06-14
  • 2022-03-03
相关资源
相似解决方案