I am trying generate even fibonacii numbers less than four million, but I keep getting negative numbers at some point and eventually it converges to a positive answer, which is obviously wrong. Can anyone please help me out?
#include <conio.h>
#include <stdio.h>
void main (void)
{
clrscr();
int f1=1;
int f2=1;
long temp=0;
long total=0;
while (temp<4000000))
{
temp=f1+f2;
f1=f2;
f2=temp;
if (temp%2==0)
{
printf("\n %d",temp);
}
}
getch();
}