fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. double fdif(double x,double y)
  5. {
  6. return x+y;
  7. }
  8.  
  9. int main()
  10. {
  11. double k1, k2, k3, k4, dy, x, y0, a, b, h;
  12. scanf("%lf %lf %lf %lf", &a, &b, &h, &y0);
  13. for ( x ; x <= b ; x += h )
  14. {
  15. k1 = fdif (x , y0);
  16. k2 = fdif (x + h / 2 , y0 + h / 2 * k1);
  17. k3 = fdif (x + h / 2 , y0 + h / 2 * k2);
  18. k4 = fdif (x + h , y0 + h * k3);
  19. y0 += h * ( k1 + 2 * k2 + 2 * k3 + k4 ) / 6;
  20. }
  21. printf("%lf", y0);
  22. return 0;
  23. }
Success #stdin #stdout 0s 3300KB
stdin
0.0 0.5 0.1 1.0
stdout
1.797441