public double sqrt(double input, double errorFactor = 0.00001) { double min = 0; double max = input input) { max = current_result; } else { min = current_result; } } while ((current_result_sq >= input - errorFactor && current_result_sq <= input + errorFactor) == false); return Math.Round(current_result, 4); } } } Test cases [TestMethod()] public void sqrtTest1() { SquareRoot target = new SquareRoot(); double input = 9F; double errorFactor = 0F; double expected = Math.Round(Math.Sqrt(input), 4); double actual; actual = target.sqrt(input, errorFactor); Assert.AreEqual(expected, actual); } [TestMethod()] public void sqrtTest2() { SquareRoot target = new SquareRoot(); double input = 0.9; double expected = Math.Round(Math.Sqrt(input),4); double actual; actual = target.sqrt(input); Assert.AreEqual(expected, actual); } [TestMethod()] public void sqrtTest3() { SquareRoot target = new SquareRoot(); double input = 7F; double expected = Math.Round(Math.Sqrt(input), 4); double actual; actual = target.sqrt(input); Assert.AreEqual(expected, actual); } [TestMethod()] public void sqrtTest4() { SquareRoot target = new SquareRoot(); double input = 4F; double expected = Math.Round(Math.Sqrt(input), 4); double actual; actual = target.sqrt(input); Assert.AreEqual(expected, actual); }

This is implemented using Newton Raphson's Method:- def sqrt(n) low = 0 high = n mid = ((low+high)/2).to_f while (mid*mid-n).abs.to_f > 0.00001 if ((mid*mid).to_f n) high = mid end mid = ((low + high)/2).to_f end return mid end

This is implemented by iterations double sqrt(double x) { double old = x; double eps = 0.000001; int it = 0, itmax = 100000; do { if(++it > itmax) break; double new = (old + x/old)/2; } while (abs((new/old - 1)> 0.00001)) } return new; }