Skip to content

Instantly share code, notes, and snippets.

@0xeuclid
Created October 26, 2012 09:41
Show Gist options
  • Save 0xeuclid/3957872 to your computer and use it in GitHub Desktop.
Save 0xeuclid/3957872 to your computer and use it in GitHub Desktop.
Simple function as argument.
//Simple function as argument.
// [email protected]
#include<stdio.h>
double f(double x);
double sum_square(double (*)(double x), int lower, int upper) ;
int main(){
printf("%lf\n",sum_square(f,1,10));
return 0;
}
double f(double x){ return 1.0 / x; }
double sum_square(double f(double x), int lower, int upper){
double sum=0.0 ;
int k=0;
for(k=lower;k<=upper;++k){
sum += (*f)(k) * (*f)(k) ;
}
return sum ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment