fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double f(double x, double y) {
  5. return y * (y - 1.0)/x;
  6. }
  7. const int n = 50;
  8.  
  9. int main()
  10. {
  11. int i;
  12. double x, y;
  13. double a, b, h, eps, k1, k2, k3, k4;
  14.  
  15. a=1.0;b=2.0;h=(b-a)/n;
  16. x=a;y=0.5;
  17.  
  18. for (i = 1; i <= n; i++)
  19. {
  20. k1=f(x,y);
  21. y=y+h*f(x+h/2.0, y+(h/20)*k1);
  22. x=x+h;
  23.  
  24. }
  25. eps=1.0/3.0-y;
  26. printf("x = %.16lf\n", x);
  27. printf("eps = %.16lf\n", eps);
  28. return 0;
  29. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
x = 2.0000000000000009
eps = 0.0001472024732824