Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <stdio.h>
- static double f(double x) { return cos(-x * x); }
- int main(void) {
- const int n = 10000;
- const double a = -1., b = 1., h = (b - a) / n;
- double s = f(a) + f(b);
- for (int i = 1; i < n; ++i) { s += (i % 2 ? 4 : 2) * f(a + i * h); }
- s *= h / 3;
- printf("%.17f\n", s);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement