看了好久,没发现什么问题啊,但为什么输出的结果差距这么大?
#include <stdio.h>#include <stdarg.h>
float average(int num,...);
int main(void) //看了好久,没发现什么问题啊,但为什么输出的结果差距这么大?
{ //结果:The first average is 42.30
float x; // The second average is 39705780.00 为什么呢???
x=average(10,12,23,34,56,245,3,4,6,3,34);
printf("The first average is %f\n",x);
x=average(25,23,23,3,24,23);
printf("The second average is %f",x);
getchar();
return 0;
}
float average(int num,...)
{
int count,total=0;
va_list arg_ptr;
va_start(arg_ptr,num);
for(count=0;count<num;count++)
total+=va_arg(arg_ptr,int);
va_end(arg_ptr);
return ((float)total/num);
}