I am trying to compute the integral of the function f(x)=(1-x^2)^(1/2) from x=0 to x=1. The answer should be approximately pi/4. I am currently getting 2.

My current implementation of the trapezoidal rule is the following:

![](https://latex.codecogs.com/gif.latex?F=%5Csum_%7Bi=0%7D%5E%7BN-1%7D0.5(x_i_+_1-x_i)(f(x_i)+f(x_i_+_1)) "F=\sum_{i=0}^{N-1}0.5(x_i_+_1-x_i)(f(x_i)+f(x_i_+_1))")

```
double
def_integral(double *f, double *x, int n)
{
  double F;
  for (int i = 0 ; i < n ; i++) {
    F += 0.5 * ( x[i+1] - x[i] ) * ( f[i] + f[i+1] );
  }
  return F;
}

```

I'm creating N divisions to approximate the area under the curve between x\_1=0 and x\_N=1 by looping through i to N with x\_i = i / N.

```
int
main(int argc, char **argv)
{
  int N = 1000;
  double f_x[N];
  double x[N];

  for (int i = 0 ; i <= N ; i++) {
    double x = i * 1. / N;
    f_x[i] = sqrt(1. - pow(x, 2.));
    //printf("%.2f %.5f\n", x, f_x[i]); //uncomment if you wanna see function values
  }

  double F_x = def_integral(f_x, x, N);

  printf("The integral is %g\n", F_x);
}

```

The result of 2 that I am currently getting should be dependent on the number of N division, however, no matter if I make N=10000 or N=100, I still get 2.

Any suggestions?