Find square root of a number upto given precision value.
1. Begin with an arbitrary positive starting value "Guess" G (the closer to the actual square root of N, the better).
2. Let Result R be the average of G and N / G (using the arithmetic mean to approximate the geometric mean).
3. Repeat step 2 until the desired accuracy is achieved.
R = (G + N/G) / 2;
Code input/output:
Number: 16.0
Precision: 0.0050
Result: 4.0000001858445895
1. Begin with an arbitrary positive starting value "Guess" G (the closer to the actual square root of N, the better).
2. Let Result R be the average of G and N / G (using the arithmetic mean to approximate the geometric mean).
3. Repeat step 2 until the desired accuracy is achieved.
R = (G + N/G) / 2;
Code input/output:
Number: 16.0
Precision: 0.0050
Result: 4.0000001858445895
No comments:
Post a Comment