(20 points)Write your own square root function named double my_sqrt_1(double n)
ID: 3562917 • Letter: #
Question
(20 points)Write your own square root function named double my_sqrt_1(double n) using the following pseudocode:
x = 1
repeat 10 times: x = (x + n / x) / 2
return x
and then write a main which prints n, sqrt(n), and my_sqrt_1(n) for n =
? times 10 to the kth power for k = -100, -10, -1, 0, 1, 10, and 100. Use this C++11 code (which may not work on Visual Studio):
for(auto k : {-100, -10, -1, 0, 1, 10, 100}){
n = M_PI * pow(10.0, k);
//cout goes here
}
Note: my_sqrt_1(n) is based on the Newton-Raphson algorithm.