【在线==】求救!请教函数指针!
程序代码:#define N 12
#include
float arr_add(float arr[],int n)//求数组元素之和
{
int i;
float sum = 0;
for(i=0; i<N; i++)
sum += arr[i];
return sum;
}
float odd_add(float *p,int n)//求下标为奇数的元素之和
{
int i;
float sum = 0;
for(i=0; i<N;I=I+2,P=P+2)
sum = sum + *p;
return sum;
}
void process(float *p,int n,float (*fun)( ))//利用函数地址作参数
{
float result;
result = ( * fun )(p,n);
printf("%8.2f\n",result);
}
int main()
{
static float a[] = {1.5,3.8,5.6,7.8,91.6,1.61,13.3,15.0,17.5,19.9,21.7,23.0};
float arr_add(),odd_add();
void process(float *p,int n,float(*fun)());
int n = N;
process(a,n,arr_add);
process(a,n,odd_add);
return 0;
}
//运行有错误啊,看来函数指针还是没弄懂,求高手指导下!谢谢!
void process(float *p,int n,float (*fun)( ))此句有错误,
错去信息:error C2197: 'float (__cdecl *)(void)' : too many actual parameters
我是VC的!








