-->
当前位置:首页 > 题库

PROGRAMMING:Calculating the square root of n

Luz5年前 (2021-05-10)题库503
Heron method is a method used by ancient Greeks to calculate the square root of a number n. This method produces a series of values that constantly approach $$- sqrt {n} $$. The first value in the sequence is an arbitrary guess value, and other values are calculated according to the previous value prev
$$ \frac{1}{2}(prev + \frac{n}{prev})$$
Enter two numbers: N and error. The initial guess is 1.0. Repeat the calculation until the difference (absolute value) between the two adjacent approximations is less than or equal to error. Output the square root of n.
###Input format:
Enter N and error
###Output format:
Square root of output n
###Input sample 1:
Here is a set of inputs. For example:
```in
four
zero point five
```
###Output sample 1:
The corresponding output is given here. For example:
```out
two point zero five
```







answer:If there is no answer, please comment