fork(72) download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. double num = 570.15;
  5. double root = num / 2;
  6. double eps = 0.01;
  7. int iter = 0;
  8. while( root - num / root > eps ){
  9. iter++;
  10. root = 0.5 * (root + num / root);
  11. printf("Iteration: %d : root = %f\n", iter, root);
  12. }
  13. printf("root = %f", root);
  14. return 0;
  15. }
  16.  
Success #stdin #stdout 0s 4568KB
stdin
Standard input is empty
stdout
Iteration: 1 : root = 143.537500
Iteration: 2 : root = 73.754816
Iteration: 3 : root = 40.742579
Iteration: 4 : root = 27.368269
Iteration: 5 : root = 24.100394
Iteration: 6 : root = 23.878842
root = 23.878842