Advertisement
cd62131

definite integral cos(-x^2) dx from x=-1 to 1

Jul 4th, 2019
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.32 KB | None | 0 0
  1. #include <math.h>
  2. #include <stdio.h>
  3. static double f(double x) { return cos(-x * x); }
  4. int main(void) {
  5.   const int n = 10000;
  6.   const double a = -1., b = 1., h = (b - a) / n;
  7.   double s = f(a) + f(b);
  8.   for (int i = 1; i < n; ++i) { s += (i % 2 ? 4 : 2) * f(a + i * h); }
  9.   s *= h / 3;
  10.   printf("%.17f\n", s);
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement