Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write your own squareroot function named double my_ squareroot _1(double n) usin

ID: 3847738 • Letter: W

Question

Write your own squareroot function named double my_ squareroot _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, squareroot (a), and my_ squareroot _1(n) for n = 3.14159 times 10 to the k^th power for k = -100, -10, -1, 0, 1, 10, and 100. Use this C ++ 11 code (which may not work on older version of Visual Studio): for(auto k: {-100, -10, -1, 0, 1, 10, 100}){ n = 3.14159 * pow(10.0, k);//cout goes here } Modify problem 1 to also print the relative error as a per cent, by adding a column relative_error_per_cent = 100 * ((my_ squareroot _1(n)- squareroot (n))/ squareroot (n). Line up the column using setw(), etc. Name your program hw2pr2.cpp.

Explanation / Answer

    for (int i = 0; i < 10; ++i)

x = (x + n / x) / 2;

#define _USE_MATH_DEFINES