Newton’s method of calculating a square root.
5² = 25, so √25 = 5, or expressed another way, 5 * 5 = 25, so the square root of 25 is 5. Newton’s method is one way to calculate the square root of a number.
Write a program that outputs the square root of a number using Newton’s method.
Use this boilerplate code as a starting point:
Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.
For example, the square root of 64 can be calculated in the sequence of steps:
8.0 – This value equals the previous value of root, so the algorithm is complete.
Enter a number: 25
The square root of 25.0 is 5.0
Enter a number: 64
The square root of 64.0 is 8.0
Use these resources as a reference to help you meet the success criteria.
Run the unit tests below to check that your program has met the success criteria.
Enter a number: 18.49
The square root of 18.49 is 4.3
Enter a number: 36
The square root of 36.0 is 6.0
Enter a number: 49
The square root of 49.0 is 7.0
Enter a number: 200
The square root of 200.0 is 14.142135623730951
Check that you have: