Files
cmlab/6.c
Amneesh Singh be590b5cfd exp 1-6: init
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
2022-12-26 19:14:30 +05:30

24 lines
491 B
C

#include <math.h>
#include <stdio.h>
#define f(x) ((352 * x * x * x) - (64 * x * x) + (198 * x) - 36)
double trapezoidal_integral(double a, double b, double n) {
double h = (b - a) / n;
double s = (f(a) + f(b)) / 2;
// Add the other heights
for (int i = 1; i < n; i++)
s += f(a + i * h);
return s * h;
}
int main() {
printf("The area under the curve f(x) = 352x^3 - 64x^2 + 198x - 36 from x=3 "
"to x=4 is %lf",
trapezoidal_integral(3, 4, 10000));
}