Euler Project
Lets say you wanted to calculate the sum of every even number in the Fibonacci sequence under 4 million. I believe this bit of code (c#) would do that. Why would you want to? I don't know.
double gr = (1 + Math.Sqrt(5))/2;
double sum = 0;
double fib = 0;
double c = 0;
while (fib < 4000000)
{
sum += fib;
c+=3;
fib = Math.Round((((Math.Pow(gr,c))/Math.Sqrt(5)) + (1/2)), 0);
}
Console.WriteLine("Sum = {0}", sum);
Labels: code
0 Comments:
Post a Comment
<< Home