fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main (void)
  7. {
  8. double a,b,x1,x2,f1,f2,dx,P=0;
  9. int n=100;
  10.  
  11. cout<<"podaj a :";
  12. cin>>a;
  13. cout<<"podaj b :";
  14. cin>>b;
  15.  
  16. dx=(b-a)/n;
  17. x1=a;
  18. x2=x1+dx;
  19. f1=sin(x1);
  20. f2=sin(x2);
  21. for (int i=0; i<n; i++)
  22. {
  23. P=P+((f1+f2)*0.5*dx);
  24. x1=x2;
  25. x2=x1+dx;
  26. f1=f2;
  27. f2=sin(x2);
  28. }
  29. cout<<P;
  30. }
  31.  
Success #stdin #stdout 0.02s 2860KB
stdin
-1
1
stdout
podaj a :podaj b :9.97468e-16