fork(15) download
  1. #include <iostream>
  2. #include<iomanip>
  3. using namespace std;
  4.  
  5. double f(double x)
  6. {
  7. return (2*x*x*x-7*x+4);
  8. }
  9. int main()
  10. {
  11. double a,b;
  12. int n;
  13. cin>>a>>b>>n;
  14. double s=(f(a)+f(b))/2;
  15. double h=(b-a)/n;
  16. for (int i=1; i<=n-1; i++)
  17. {
  18. s+=f(a+i*h);
  19. }
  20. double I=h*s;
  21.  
  22. cout<<setprecision(10)<<I<<endl;
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 3432KB
stdin
0 2 5000
stdout
2.00000032