- Engineering
- Computer Science
- this program supposes to do this quotfibonacci sequence starts with...
Question: this program supposes to do this quotfibonacci sequence starts with...
Question details
This program supposes to do this
"Fibonacci sequence starts with 0 and 1 where each fibonacci number is a sum of two previous fibonacci numbers. Given an integer N, find the sum of all even fibonacci numbers."
Example) input = 12
output = 10 because 2 + 8 = 10
In this program, n is for nth fibonacci number and sum is for sum of all even numbers that question asked for.
However, I always got the 0 for the sum value ( nth number prints out correct all the time).
I don't know why this happens.
Can someone explain it to me why this method can't calculate the sum and also what am I suppose to fix it??
This is C++ fyi.
Thank you :)
Solution by an expert tutor
