Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Complete the implementation of the fibonacci function. This activity will help you 1earn how to use counter controlled loops, arrays, global variables, and carry out
Complete the implementation of the fibonacci function. This activity will help you 1earn how to use counter controlled loops, arrays, global variables, and carry out operations involving simultaneous access to multiple elements of a single array This program populates array term with the first 32 terms of a Fibonacci-like sequence, starting from initial seed values term[0] = X, term 1]-Y, where X and Y are integer values which are supplied to the program via standard input The general design of your program is as follows . Global variables: o term: an array with capacity to hold 32 values of type int o fibonacci expects no arguments. o fibonacci produces no result (i. e. the return type is void) o Read two integer values from standard input, and store then in the first two elements of the array, in the order they are received. Parameters . Returns - Process: Standard library function scanf may used for this purpose. Do not emit any kind of prompt; this program will not be executed interactively .If it makes you feel more comfortable, you can display a prompt. It will be ignored by AMS The values supplied when AMS tests your program are guaranteed to be valid integers, separated by spaces, with values between 1 and 30 inclusive. Error detection or input validation is not required for this exercise. o Populate the remainder of the array with the consecutive terms of the Fibonacci-like sequence grown from the seed values. To do this, use a counter-controlled loop which will visit every element of term from the third to the last The Fibonacci term at position t is equal to the sum of the terms at positions (t-1) and (t-2) Test plan o Test your program with several seed pairs, including: (1,1), (30,30), and some pairs involving intermediate values such as (3,9) o Verify the correctness of your results by computing a few terms by hand, or by se alternate but reliable method such as a spreadsheet program. o Use input redirection to supply data to the standard input stream of your program. There are several ways to do this. One easy way is to pipe the output of the echo command into your program. For example, to send a single line containing the seed pair (5,9) to the test driver, use the following command echo -n "5 9" | ./fibonacci Notes .A program similar to yours produces the output sequences pictured below. The images illustrate a convenient way to invoke the test driver using input redirection to provide the seed values for reading via scanf. Your results will not be exactly the same as this view, because each user gets a unique set of parameters. However, it should give you an idea what to aim for bash echo -n "1 1" |/fibonacci 5 8 13 21 34 89 144 233 377 610 987 1597 2584 4181 6765 10946 28657 bash echo -n "1 10"| ./fibonacci 10 21 32 53 85 138 21 32 53 85 138 223 361 584 945 1529 2474 4003 6477 10480 16957 27437 44394 71831 116225 188056 bash echo -n "5 3" /fibonacci 5 8 19 30 49 79 128 207 335 542 877 1419 2296 3715 6011 9726 15737 25463 49 79 128 207 335 542 877 1419 2296 3715 6011 9726 15737 25463 41200 66663 107863 bash $echo -n "30 29" ./fibonacci 30 29 59 147 235 382 617 1616 2615 4231 6846 11077 17923 29000 46923 75923 122846 198769 321615 520384 Use this test driver to implement and test your function prior to submission. #include #include
Step 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