/* Trapezoid algorithm to approximate integral of F(x)=x+1 over [a,b] */ #include #include double Func(double x) { return (x+1); } void main() { double total, //total area of the interval h, // size of each sub-interval sum, // Value of approximation a,// left end b,// right end x;// variable int i,n; b=1.0; a=0.0; n=10; sum=0.5*(Func(a)+Func(b)); h=(b-a)/n; for(i = 1; i<= n-1; i++) { x= a+i*h; sum=sum+Func(x); // Trapezoid rule formula } sum=h*sum; printf("Approximation is=%f\n", sum); }