Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

image text in transcribed

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.

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

5. Develop the succession planning review.

Answered: 1 week ago