Sie sind auf Seite 1von 1

yes.

/* trapezoid.c */
include <stdio.h>
include <math.h>
float f(float);
float a; float b; float x; float h; float sum; int n; int i;
int main() {
printf("Enter value for a: "); scanf("%f", &a);
printf("Enter value for b: "); scanf("%f", &b);
printf("Enter number of rectangles: "); scanf("%d", &n);
h = (b - a) / n;
sum = (0.5 * h) * (f(a) + f(b)); printf("%f\n", sum);
for (i = 1; i < n; i++) {
sum = sum + h * f(a + (i * h)); printf("%f\n", sum);
}
printf("The value of the integral is: %f\n", sum);
}
float f(float x) {
float value;
/* define function here */ value = x*x + 3;
return value;
}

Das könnte Ihnen auch gefallen