Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. #include <iostream>
  2. #include<cmath>
  3. using namespace std;
  4.  
  5. double f (double a)
  6. {
  7. return sin(a);
  8. }
  9.  
  10. double trapezy(double a, double b, int N)
  11. {
  12. double h = (b-a)/N;
  13. double P = (f(a)+f(b))/2;
  14. for(int i=1; i<N; i++)
  15. P += f(a+i*h);
  16. return P*h;
  17. }
  18. main()
  19. {
  20. for(int i=100; i<10000000; i*=10)
  21. {cout.precision(15);
  22. cout<<trapezy(0, M_PI, 1000000)<<endl;}
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement