Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The C++ code below uses float type variables x, y, z, and square. It computes th

ID: 3722655 • Letter: T

Question

 The C++ code below uses float type variables x, y, z, and square. It computes the square root of the variable square by repeatedly moving x and y closer together so that x*x <= square and y*y >= square until they are so close that either one could be used as the square root.  Complete the code below by making the compound statement {...} into a do/while loop that continues until the difference y-x is smaller than 0.001.  You may use the literal constant 0.001 in your answer.    x = 0.0;   y = 100.0;       {      z = (x + y) / 2.0;      if (z*z > square)        y = z;      else        x = z;     } 

Explanation / Answer

float x, y, z, square=0.0;
x = 0.0;
y = 100.0;

do
{
z = (x + y) / 2.0;
if (z*z > square)
y = z;
else
x = z;
}while((y-x) >= 0.001);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote