```
int sqrt(int x) {
double ans = x;
double delta = 0.0001;
while (fabs(pow(ans, 2) - x) > delta) {
ans = (ans + x / ans) / 2;
}
return ans;
}
```

The key point is the average result is calculate by "ans = (ans + x / ans) / 2";

For instance, when calculate sqrt(2) :

```
Guess Result Quotient Average Result
1 2 / 1 = 2 (2 + 1) / 2 = 1.5
1.5 2 / 1.5 = 1.3333 (1.3333 + 1.5) / 2 = 1.4167
1.4167 2 / 1.4167 = 1.4118 (1.4167 + 1.4118) / 2 = 1.4142
... ...
```