这是一个项目欧拉问题。如果你不想看到候选解决方案,请不要在这里查看。
大家好!我正在开发一个应用程序,将找到斐波那契数列的所有偶数项的总和。该序列的最后一项为4,000,000。我的代码有些问题,但我无法找到问题,因为它对我来说是有意义的。你能帮帮我吗?
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
long[] arr = new long [1000000] ;
long i= 2;
arr[i-2]=1;
arr[i-1]=2;
long n= arr[i];
long s=0;
for (i=2 ; n <= 4000000; i++)
{
arr[i] = arr[(i - 1)] + arr[(i - 2)];
}
for (long f = 0; f <= arr.Length - 1; f++)
{
if (arr[f] % 2 == 0)
s += arr[f];
}
Console.Write(s);
Console.Read();
}
}
}