Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Programming - Conditional Statements & Loops Write a C program which creates a 20 -element array of unsigned integers, called fib, and stores within

C Programming - Conditional Statements & Loops

image text in transcribed

Write a C program which creates a 20 -element array of unsigned integers, called fib, and stores within the array the first 20 values of the Fibonacci sequence. Look up this sequence to understand how it works. You may manually initialize the first two elements of the array to be 0 , and 1, but the remaining 18 elements should be calculated using a for-loop. You must use a 1D array for variable fib in this problem. Print out the values of the array to the Terminal Window, displaying the first 10 elements on one line, and the remaining 10 elements on the second line. Set the conversion character widths of the printf( ) statement to nicely align the columns of the print output; do not use tab characters. Sample output is provided below: Revise your code for the 1st problem to work for any number of Fibonacci values up to 20 . You can still define the array size to always be a length 20 , but you should prompt the user for the number of Fibonacci values to compute and display. You may still use a for-loop to print the data in this problem, but the length of the loop will be determined by the user. To obtain the number of values to display, we will use the scanf() command. First create an integer variable called len. Next, display a prompt to the user using printf( ) and then then run the following command: scanf ("%d",&len); to obtain the number of values to print. The scanf( ) command will halt the execution of the code until the user enters a number and presses the return key. Perform error checking on the scanned input value. If the user enters a value below 5 or above 20, display an error message with printf( ) and then re-prompt and re-scan. This process should continue until a valid length is obtained (use a while-loop). See the representative outputs below. How many Fibonacci numbers would you like? 4 Error: please enter a value between 5 and 20 . How many Fibonacci numbers would you like? 22 Error: please enter a value between 5 and 20

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

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions