Question: 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.


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 :)
#include iostream 10 11 using namespace std; 12 13 int fib( int n); 14 15 int sum; 17 int main) 18 19 20 21 cout n cout
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
