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 coutStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started