Finding Fibonacci sequence in C#. [Project Euler Exercise]

后端 未结 9 2486
后悔当初
后悔当初 2021-02-06 19:22

I\'m having some trouble with this problem in Project Euler.

Here\'s what the question asks:

Each new term in the Fibonacci sequence is generated by adding t

9条回答
  •  忘掉有多难
    2021-02-06 19:42

    int sum = 2;
    for(int f1 = 1, f2 = 2, f3 = 0; !((f3 = (f1 + f2)) > 4000000); f1 = f2, f2 = f3)
        sum += f3 * (~f3 & 1);
    

提交回复
热议问题