Skip to main content

Exercises 19.9 Chapter Exercises

1.

Fix the errors so it runs and returns the perimeter of a rectangle.

2.

The areaTriangle function below was hard coded so it always uses 5 and 4 for the base and height of the triangle. Modify the function so that it has parameters for base and height and works to calculate the area of different triangles.

3.

The mathemetician Newton invented a method to approximate the square root of a number. Take the number N you want the square root for and a guess G and then calculate \(1/2(N/G + G)\text{.}\) You will get a rough approximation. If you use the answer as a new guess and repeat the process, you will get a closer approximation. You can keep repeating the process to make your approximation closer and closer to the real value.
Write an approximateSqrt function that takes a number and a guess as its parameters and then uses Newton’s formula to estimate the square root of the number.
There is already code provided to use your function to calculate the square root of 150.
You have attempted of activities on this page.