Untitled

 avatar
unknown
plain_text
a month ago
631 B
0
Indexable
#include <stdio.h>
#include <math.h>
#define f(x) (1 + x * x * x)
int main() {
    int i, n;
    float a, b, h, I, P;
    printf("Enter lower limit: ");
    scanf("%f", &a);
    printf("Enter upper limit: ");
    scanf("%f", &b);
    printf("Enter number of subintervals: ");
    scanf("%d", &n);
    h = (b - a) / n;
    I = f(a) + f(b);
    for (i = 1; i < n; i++) {
        P = a + i * h;
        if (i%2==0){
          I=I+2*f(P);
        }
        else {
            I=I+4*f(P);
        }
    }
    I = (h / 3) * I;
    printf("The required value of the integration is: %.4f\n", I);
    return 0;
}
Editor is loading...
Leave a Comment