A more general way (to call a variety of functions):
float z(float);
float g(float);
float Integrator(float f(float),float
a, float b, float precision, int max_iterations);
int main(void)
{
float a,b,precision,Ig,Iz;
int max_iterations;
....
/* do stuff; initialize a,b,precision,max_iterations */
Ig= Integrator(g,a,b,precision,max_iterations);
/* integrate g(x) */
Iz= Integrator(z,a,b,precision,max_iterations);
/* integrate z(x) */
....
/* do some more stuff, maybe print out the values of the integrals */
/* This version of Integrator can
integrate functions with any name, not just f(x): */
float Integrator(float f(float x),
float a,float b,float precision, int max_iterations)
{
float xi,h,sum,ci;
...
/* initializations, and a loop whose key line is: */
sum=sum+ci*(f(xi));
/* this calls the function who's memory address
was passed down as an argument to Integrator */
/* It doesn't have to be called f() ! */
...
/* end the loop, then when everything has converged,
return the value of the integral "sum" */
return sum;
}
/* this is explained in ABC 6.16 ff */