Implement "double sqrt(double x)" in C++.
Anonymous
here is the code: #include double sq(double x){ double mx = 32000; double mn = 0; while(mx - mn > 1e-9){ double md = (mx + mn) / 2; if(md * md > x) mx = md; else mn = md; } return mx; } int main(){ while(1){ double db; scanf("%lf",&db); printf("%lf\n",sq(db)); } }
Check out your Company Bowl for anonymous work chats.