Archive for March 25th, 2010

Sum of even valued numbers in Fibonacci series

Up to 4 million.

int f1 = 0;
int f2 = 1;
int temp = 0;
int sum = 0;
for (int i = 0; sum < 4000000;i++)
{
temp = f1 + f2;
f1 = f2;
f2 = temp;
if (f2 % 2 == 0)
[...]

Leave a Comment

Sum of multiples of 5 OR 3

 
int sum = 0;
for(int i=0;i<1000;i++)
 
{
if ((i % 3 == 0) || (i % 5 == 0))
{
sum += i;
}
}
 
textBox1.Text = sum.ToString();

VN:F [1.1.6_502]Rating: 0.0/5 (0 votes cast)

Leave a Comment