Advertisement
StoneHaos

maxim9(0.5)

Jun 17th, 2020
1,224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. double f(double x) {
  7.     return x * atan(x);
  8. }
  9.  
  10. int main() {
  11.     int n = 1;
  12.     double a = 0, b = 3, eps = 0.001, s_last = 0, s_cur = 0, h;
  13.     for (; n < 4 || fabs(s_cur - s_last) > eps; n <<= 1) {
  14.         h = (b - a) / n;
  15.         s_last = s_cur;
  16.         s_cur = 0;
  17.         for (int i = 1; i <= n; ++ i) {
  18.             s_cur += h * f(a + (i - 0.5) * h);
  19.         }
  20.     }
  21.     cout << s_cur << endl;
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement