Question: Program 1: Fibonacci -- Getting Started Motivation This program serves as a first introduction to C, focusing on both basic I/O and control flow structures.

 Program 1: Fibonacci -- Getting Started Motivation This program serves asa first introduction to C, focusing on both basic I/O and control

Program 1: Fibonacci -- Getting Started Motivation This program serves as a first introduction to C, focusing on both basic I/O and control flow structures. Overview The Fibonacci sequence is a well known integer sequence which is computable via iterative, recursive, or closed form methods. Your program will read in a value, n, and then print the nth Fibonacci number. This process will be repeated until the user enters a 0. For our purposes, Fibonacci number is 0, with numbers 1 and 2 defined to both be 1, and the remaining values computed as usual. Program Requirements Your program must be written in C and compile using gee 's -std=c99 -Wall, and -pedantic flags. Read input from the terminal (using scanf ) and write output to the terminal (using printf ). You may use whatever method you choose to compute the Fibonacci numbers, so long as your program responds in a reasonable amount of time. There is a closed form you can make use of, if you like: where y = 2 (Yes, that's p (phi), the Golden Ratio.) 1+/5 75 Fn = "_(*) Your program may make use of the functions in the math library (math.h). If you wish to use the math functions, you will need to compile your program with the - Lm option. We will supply this option when we compile your program for grading. Input Specification Your program will be expected to process one or more input cases. For each input case, print the prompt "Value: "and read in an integer value on the same line. If the value is negative, immediately reprint the prompt and read in another value. Repeat this until a non-negative value is read. Continue prompting and calculating Fibonacci values until a 0 is seen, at which point you should print the oth Fibonacci value (0) and exit. You may assume that no value higher than 45 will be input. Output Specification Once you have computed the nth Fibonacci value, print out the string "Fibonacci number n is Fn" followed by a single blank line, replacing the literal n with the value you read, and Fr with the nth Fibonacci number. Sample Run Value: 1 Fibonacci number 1 is 1 Value: 5 Fibonacci number 5 is 5 Value: 8 Fibonacci number 8 is 21 Value: 2 Fibonacci number 2 is 1 Value: -1 Value: -3 Value: 42 Fibonacci number 42 is 267914296 Value: 0 Fibonacci number is

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!