(1)说转化double to float 有问题;(2)子函数名为什么不能用y1?
#include<stdio.h>#include<math.h>
float y2(float x)
{
float y;
y=sin(x);
return(y);
}
float y3(float x)
{
float y;
y= cos(x);
return(y);
}
float y4(float x)
{
float y;
y=exp(x);
return(y);
}
void process(float a,float b, float (*fun)(float) )
{
float x,d,sum=0,z,i,k=10000;
d=(b-a)/k;
for(i=0;i<=k;i++)
{
x=a+d*i;
z=(*fun)(x);
sum+=z*d;
}
printf("%5.1f\n",sum);
}
void main()
{
float a,b;
scanf("%f,%f",&a,&b);
process(a,b,y2);
process(a,b,y3);
process(a,b,y4);
}
[ 本帖最后由 xdh0817 于 2011-11-8 23:23 编辑 ]