Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

15-17 15. Write a C program getSalads to read from stdin as many lines of input as possible (each line can be assumed to be

15-17 image text in transcribed
15. Write a C program getSalads to read from stdin as many lines of input as possible (each line can be assumed to be a nonnegative integer). Do not program it in a way that would force the user to type a special number of indicate the end of inputs. The program should print the square roots of all input numbers (one per line). You can decide whether you want to print these square roots after all the input numbers have been received, or you want to print a square root as each input number is received. A sample run can look like the following (note that number of input integers and the integers themselves can be arbitrary): $ ./getSalad enter some nonnegative integers: 1 The square root of 1 is 1.000000 2. The square root of 2 is 1.414214 3 The square root of 3 is 1.732051 5 The square root of 5 is 2.236068 16. Suppose you have written your previous C program getsalad.c and it works fine as long as each input number is nonnegative. But you know your program might behave unexpectedly if any input number is negative. How would you modify your code so that it will abort and report the unfortunate situation when a negative number is input? 17. Suppose you have written a C program getBread.c and it reads from stdin as many lines of input as possible (each line can be assumed to be a nonnegative integer). Similar to the behavior of the previous program getSalads, the program should compute and print the values of some function of all input numbers (one per line). The math function fis much more complicated than the square root function and you want to test your own implementation of this function in the program on a selected set of 50 Input Integers and see whether it produces the correct outputs. The program may have bugs and you may need to revise the code and test it many times on those 50 integers. What would you do, other than hard-coding the 50 integers into your program source code, to avoid re- typing the 50 input integers each time you want to test your code after revising and re-compiling it

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

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions

Question

1. Prepare a flowchart of Dr. Mahalees service encounters.

Answered: 1 week ago