0
Why does this code work?
double squareRoot(double num) { double low = 1.0; double high = num; for (int i = 0; i < 30; i = i + 1) { double estimate = (high + low) / 2; if (estimate*estimate > num) { double newHigh = estimate; high = newHigh; } else { double newLow = estimate; low = newLow; } } return (high + low) / 2; } int main () { cout << squareRoot(9); //Enter the number that you want to take square root of. }
3 Answers
+ 1
Don't all programmers ask that question : "why does this code work?"
0
is it working or not working ! ..?
0
It is working but I don't understand why it works. If you plug the number you want to take square root of, it operates sucessfully. So I was wondering if someone could explain the code



