15,922,407 members
See more:
I got a challenge from www.hackerrank.com, calculate the sum of even Fibonacci number. I have submitted the logic that will calculate even Fibonacci numbers but i have used the loop to calculate the sum. Is there any mathematical logic that will calculate sum of even Fibonacci number without looping. Thanks in advance.
Posted
Patrice T 9-Oct-15 4:10am
Show your code, it may be possible to optimize.

## Solution 1

No.
Well, that's not true, you could make it a recursive algorithm instead, but...that's even less efficient.

Fibonacci numbers are a sequence - each term depends on the two value of the two previous terms. So in order to evaluate F(n), you need to know both F(n-1) and F(n-2), both of which depend on two earlier terms.

So no, you can't magically find the value of F(n) without a loop being involved. Unless you use that loop to generate all the values in advance and store them for your app to access - but since the sequence is unbounded, you don;t have space for that...:laugh:

## Solution 2

Since the `Fibonacci` series is easily generated with a loop, I wouldn't even bother if there are alternate algorithms (simplex sigillum veri). However you might try recursion. It is a pity the C# programming language doesn't support tail recursion optimization...Oops, wait... "Tail recursion in C#"[^].

v2