Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task D. Computing Fibonacci Numbers with Loops and Arrays 0, 1, 1, 2, 3, 5, 8, 13 First, a quick intro: Fibonacci numbers is a

Task D. Computing Fibonacci Numbers with Loops and Arrays 0, 1, 1, 2, 3, 5, 8, 13

First, a quick intro:

Fibonacci numbers is a sequence of numbers that starts with F(0) = 0 and F(1) = 1, with all the following numbers computed as the sum of two previous ones, F(n) = F(n1) + F(n2):

0 1 1 (=1+0) 2 (=1+1) 3 (=2+1) 5 (=3+2) 8 (=5+3) 13 (=8+5) and so on

To make a C++ program to keep track of the previous numbers so that we can compute the new ones, we can use an array of integers:

// make an array int fib[60]; // first two terms are given fib[0] = 0 fib[1] = 1 // and all the following ones can be computed iteratively as fib[i] = fib[i-1] + fib[i-2] 

The task:

Write a program fibonacci.cpp, which uses an array of ints to compute and print all Fibonacci numbers from F(0) to F(59).

Example:

0 1 1 2 3 5 8 13 ... 

Once your program is complete and works, check carefully the values printed on the screen. Specifically, what is happening when the numbers approach two billions? We expect that at some point the numbers start diverging from what they should be. Describe what you observe and explain why it is happening in a program comment.

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

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

Understand the process of user interface design.

Answered: 1 week ago

Question

5. Recognize your ability to repair and let go of painful conflict

Answered: 1 week ago