# # Compute a square root of a number # and compare the result with standard sqrt(x) function # func main() while (0 == 0) # Infinite loop print("Input a number (0 for the end): "); x = double(scan()); if (x == 0.) break; endif y = squareRoot(x); println("squareRoot(x) = ", y); println("standard sqrt(x) = ", sqrt(x)); endwhile endfunc # Compute a square root using Newton iterations func squareRoot(a) println(" in squareRoot: a = ", a); if (a < 0.) println(" Incorrect argument"); return 0.; endif EPS = 0.0000001; x = a; if (x < 1.) x = 1.; endif xPrev = x + 1e100; while (fabs(xPrev - x) > EPS) xPrev = x; x = (x + a/x) / 2.; println(" ", x); endwhile println(" in squareRoot: result = ", x); return x; endfunc # Starter main();