Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- double f(double x) {
- return x * atan(x);
- }
- int main() {
- int n = 1;
- double a = 0, b = 3, eps = 0.001, s_last = 0, s_cur = 0, h;
- for (; n < 4 || fabs(s_cur - s_last) > eps; n <<= 1) {
- h = (b - a) / n;
- s_last = s_cur;
- s_cur = 0;
- for (int i = 1; i <= n; ++ i) {
- s_cur += h * f(a + (i - 0.5) * h);
- }
- }
- cout << s_cur << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement