Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Step 1: Copy this program into your C++program editor, and compile it. Hopefully you will not get any error messages. Step 2: Run the program

image text in transcribed

Step 1: Copy this program into your C++program editor, and compile it. Hopefully you will not get any error messages. Step 2: Run the program and type in the number "42" to see what it prints. You should see the square root of 42 calculated using the "sqrt" function. The second output line shows 42 raised to the power 1/2 which is another way to calculate the square root. Try several other input values. Do the two square root calculations always match each other? Step 3: Type in "man sqrt" in your Linux window (or do a google search for "c++ sqrt function") to see the manual page for this function. Near the top of the manual page you will see the function prototype "double sqrt(double x );". If you read the description you will see that the sqrt function expects one double parameter and returns a double value that is the "nonnegative square root of x ". Step 4: Type in "man pow" in your Linux window (or do a google search for "c++ pow function") to see the manual page for this function. Near the top of the manual page you will see the function prototype "double pow(double x, double y );". If you read the description you will see that the pow function expects two double parameters and returns a double value that is equal to " x raised to the power of y. Step 5: If you entered the number "4" above you saw that the square root was equal to 2, which is exactly correct. On the other hand, we can only approximate the square root of " 3 " using a double in C++because the true answer has infinite length. To see what the error in this square root calculation is, copy/paste the following two lines after the "cout sqrt" and "cout pow" lines above. error = num root root; cout

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_2

Step: 3

blur-text-image_3

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

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions