fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4.  
  5. #define EPSILON 1.0e-30
  6.  
  7. double newton(double x)
  8. {
  9. int i = 0;
  10. double eps, j = x;
  11. do
  12. {
  13. eps = (j * j * j - x) / (4.0 * j * j);
  14. j = j - eps;
  15. printf("%d, %16.32lf\n", ++i, j);
  16. } while (fabs(eps) > EPSILON);
  17.  
  18. return j;
  19. }
  20.  
  21. int main(void)
  22. {
  23. newton(9.0);
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 4412KB
stdin
Standard input is empty
stdout
1, 6.77777777777777767909128669998609
2, 5.13231210248141156426981979166158
3, 3.93465345415281841923160754959099
4, 3.09632486561154252058258862234652
5, 2.55693088900808973562561732251197
6, 2.26184560311524363029889173049014
7, 2.13618560088152031894992433080915
8, 2.09520462753817238166220704442821
9, 2.08394567086821291823639512585942
10, 2.08105464910553195068132481537759
11, 2.08032686918517617513657569361385
12, 2.08014460588083771597212034976110
13, 2.08009902009120217769577720900998
14, 2.08008762239499978008439029508736
15, 2.08008477289288284950430352182593
16, 2.08008406051247396462144934048411
17, 2.08008388241706709820277865219396
18, 2.08008383789319628576208742742892
19, 2.08008382676222725038428507104982
20, 2.08008382397948476949522955692373
21, 2.08008382328379948233987306593917
22, 2.08008382310987771646182409313042
23, 2.08008382306639738601461431244388
24, 2.08008382305552741442511432978790
25, 2.08008382305281003255004179663956
26, 2.08008382305213057605897120083682
27, 2.08008382305196048989159862685483
28, 2.08008382305191830141666287090629
29, 2.08008382305190764327562646940351
30, 2.08008382305190497874036736902781
31, 2.08008382305190409056194766890258
32, 2.08008382305190409056194766890258