Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <stdio.h>
- int main(void) {
- puts("maxN A A2 |A-A2|");
- puts("------------------------------");
- int n, maxN;
- double A, A2, x0 = 0.;
- double xn = M_PI_4;
- double x, dx;
- maxN = 1;
- while (maxN <= 100) {
- dx = (xn - x0) / maxN;
- A = A2 = 0.;
- for (n = 0; n <= maxN - 1; n = n + 1) {
- x = x0 + n * dx;
- A = A + x * sin(x) * dx;
- A2 = A2 + (x * sin(x) + (x + dx) * sin(x + dx)) * dx / 2.;
- }
- if (!(maxN % 10)) { printf("%3d %f %f %f\n", maxN, A, A2, fabs(A - A2)); }
- maxN = maxN + 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement