Next: Checkoff
Up: Loops
Previous: Searching in an Array

Computing square roots

As you recall, when we were studying DO loops for the first time we looked at how to implement a function that computes square roots via the technique of successive approximation. That program appears in ``sroot1.f'' (or view it directly). Refamiliarize yourself with the SROOT function so that you can answer the following questions.

  1. What is wrong with the way that ``SROOT'' approximates square roots?

    Click here for the answer

  2. A better approach is to compute approximations until the resulting approximation is ``good enough.'' How can we decide if the approximation is ``good enough''?

    Click here for the answer

Take a look at ``sroot2.f'' (or view it directly). It embodies a better approach to computing square roots. Run it on the numbers from above to see how it works. Then try to answer the following questions.

  1. Where is the loop in this program?

    Click here for the answer

  2. Could this loop run forever?

    Click here for the answer


Next: Checkoff
Up: Loops
Previous: Searching in an Array

Hamlet Project
hamlet@cs.utah.edu