TRAPEZOIDAL RULE IN C

//program to evaluate definite integral using trapizoidal rule
#include<stdio.h>
#include<math.h>
float fx (float x);
int main()
{
 int i,n;
 float x[10],y[10],h,sum=0.0,l,u;//l=lower limit u=upperlimt

 printf("Enter the number of sub-intervals :\n");
 scanf("%d",&n);
 printf("Enter the lower limit amd upper limit :\n");
 scanf("%f%f",&l,&u);

h=(u-l)/n;

 for(i=0;i<=n;i++)
 {
    x[i]=i*h;
    printf("x[%d]=%f\t",i,x[i]);
     y[i]=fx(x[i]);
   printf("y[%d]=%f\n",i,y[i]);
 }
sum=y[0]+y[n];
 for(i=1;i<n;i++)
       sum+=2*y[i];
sum=(h/2)*sum;

printf("Intergral value is : %f \n",sum);
return 0;
}
 float fx (float x)
{
 float f;
 f=exp(x);           //by changing this statement we can change the function as we require
return f;
}        

Comments