Applications

// Exercice 11
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define N 1000

double f(double x){
    double rho, ac;

    rho = 4000 - 7*x;
    ac = 0.01 + 5*pow(10, -5)*pow(x, 2);

    return rho*ac;
}

double trouverMasseTige(double longueur){
    int i;
    double a, b, h, s;

    a = 0;
    b = longueur;
    h = (b-a)/N;
    printf("h: %lf\n", h);
    printf("f(b): %lf\n", f(b));

    s = (f(a)+f(b))/2;
    for(i=1;i<N-1;i++){
        s += h*f(a + i*h);
    }
    return s;
}

void main()
{
    double lg;

    printf("Longueur: ");
    scanf("%lf", &lg);

    printf("Masse = %lf\n", trouverMasseTige(lg));
}