Hello everybody, I'm pretty much a beginner at using C, so my problem shouldn't be too difficult for you to solve, I hope. I wrote this program to sum all the even numbers in the fibonacci sequence below 4 million:
Code:
#include <stdio.h>
int main()
{
int current = 0;
int prev = 1;
int prev2 = 0;
int sum = 0;
do {
current += (prev + prev2);
prev2 = prev;
prev = current;
if (current%2==0){
sum += current;
}
} while (current < 4000000);
printf("The answer is %d.", sum);
getchar();
return 0;
}
When I run this program, it returns "The answer is 0.", and I can't figure out why. Any ideas?