This is a function that returns the sum of all outputs from a function f, for all integers from m to n:
double summf(int m, int n, double (*f)(int)){
double t = 0.0;
int i = m;
while(i != n)
t += (*f)(i++);
return t;
}
Here is one that gives the summation of an array of doubles:
double summa(int n, double * a){
double t = 0.0;
int i = 0;
while(i != n)
t += a[i++];
return t;
}
And finally, here is one that applies a function to the elements of an array:
double summaf(int n, double * a, double (*f)(double)){
double t = 0.0;
int i = m;
while(i != n)
t += (*f)(a[i++]);
return t;
}
What do you think?