Babylonian method for square root
why (x + y)/2 is always bigger than square root of n:
public double sqrt(double n) {
double x = n;
double y = 1;
double e = 0.0001
while (x - y > e) {
x = x + (y - x) / 2;
y = n / x;
}
return x;
}
没有评论:
发表评论