#include <stdio.h>
#include <math.h>
int main()
{float f1(float); /*函数声明*/
float f2(float); /*函数声明*/
float f3(float); /*函数声明*/
float f4(float); /*函数声明*/
float f5(float); /*函数声明*/
float intergral(float,float,float (*fun)()); /*函数声明*/
float a,b;
printf("enter a,b:"); /*输入定积分限*/
scanf("%f,%f",&a,&b);
printf("f1's value is:");
intergral(a,b,f1);
printf("f2's value is:");
intergral(a,b,f2);
printf("f3's value is:");
intergral(a,b,f3);
printf("f4's value is:");
intergral(a,b,f4);
printf("f5's value is:");
intergral(a,b,f5);
return 0;
}
float f1(float x) /*函数定义*/
{float y;
y=x*(1+x);
return(y);
}
float f2(float x) /*函数定义*/
{float y;
y=x*(2*x+3);
return(y);
}
float f3(float x) /*函数定义*/
{float y;
y=exp(x)+1;
return(y);
}
float f4(float x) /*函数定义*/
{float y;
y=(1+x)*(1+x);
return(y);
}
float f5(float x) /*函数定义*/
{float y;
y=pow(x,3);
return(y);
}
void intergral(float a,float b,float (*fun)(float)) /*函数定义*/
{float t1=a,t2=b,f_incre=0.000001,result=(fun(a))*f_incre;
while(t1<t2)
{t1=t1+f_incre;
result=result+(fun(t1))*f_incre;
}
printf("%10.6e\n",result);
}
................: error C2664: 'intergral' : cannot convert parameter 3 from 'float (float)' to 'float (__cdecl *)(void)'
[此贴子已经被作者于2007-9-8 11:41:58编辑过]