Advertisement
cd62131

definite integral

May 27th, 2019
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. #include <math.h>
  2. #include <stdio.h>
  3. int main(void) {
  4.   puts("maxN   A        A2     |A-A2|");
  5.   puts("------------------------------");
  6.   int n, maxN;
  7.   double A, A2, x0 = 0.;
  8.   double xn = M_PI_4;
  9.   double x, dx;
  10.   maxN = 1;
  11.   while (maxN <= 100) {
  12.     dx = (xn - x0) / maxN;
  13.     A = A2 = 0.;
  14.     for (n = 0; n <= maxN - 1; n = n + 1) {
  15.       x = x0 + n * dx;
  16.       A = A + x * sin(x) * dx;
  17.       A2 = A2 + (x * sin(x) + (x + dx) * sin(x + dx)) * dx / 2.;
  18.     }
  19.     if (!(maxN % 10)) { printf("%3d %f %f %f\n", maxN, A, A2, fabs(A - A2)); }
  20.     maxN = maxN + 1;
  21.   }
  22.   return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement