# fibonnaci

• May 13th, 2013, 11:21 AM
keepStriving
fibonnaci
I'm trying to calculate the following problem stuck at the moment, I don't want the answer rather would greatly appreciate if anyone could guide me to some resources which may help. I understand the problem just not sure how to represent it.

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:

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.

I'm stuck on the part about the sum of even value terms. The following is my latest attempt which I know is wrong.
Code :

```public class main{ public static void main(String[] args){   for(int i = 0;i<=33;i++){ if(i%2==0){   System.out.print(fibonnaci(i) + " "); } } } static int fibonnaci(int n){ if(n==0){ return 0; }else if(n==1){ return 1; }else{ return fibonnaci(n-1)+ fibonnaci(n-2); }   } }```
Thank you to the mod who advised me to check out project Euler, even though I'm rubbish at solving the problems, it's still great.
• May 14th, 2013, 02:16 AM
PhHein
Re: fibonnaci
You're too quick here. Break it up into little pieces. First try to gernerate the fibonacci series up to four million. When you've done that, think about how you add up the even vlues. Right now you're checkin whether the index of the sequence is even. I understand it that you have to add 2+8+34 and so on.
• May 14th, 2013, 06:18 AM
keepStriving
Re: fibonnaci
Thank you for helping, I'll try again.
• May 14th, 2013, 01:11 PM
keepStriving
Re: fibonnaci
I've solved the question, I need to spend more time contemplating what the question is asking next time.
• May 15th, 2013, 04:56 PM
jps
Re: fibonnaci
Quote:

Originally Posted by keepStriving
I've solved the question...