7.9. Chapter Exercises

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

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

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)\). 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 approcimation closer and closer to the real value.

Write an approximateSqrt function that takes a number and 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