Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
ANSWER WILL BE PUBLISHED ON : 06/07/11
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.ANSWER WILL BE PUBLISHED ON : 06/07/11
1 comments:
#include"iostream.h"
#include"conio.h"
void main()
{
clrscr();
unsigned long long res=0,f1=0,f2=1,f3=0,i=1;
while(i<4000000)
{
f3=f1+f2;
f1=f2;
f2=f3;
if(f3%2 == 0)
res=res+f3;
i++;
}
cout<<"Sum of the even terms of fibonacci series within the limit 4000000 is "<<res;
getch();
}
Note: Compiled successfully on compiler - Borland International Inc. turbo c++ 3.0
Post a Comment