标签:
#include <stdio.h>
double average(int val,int v1,int v2,int v3,int v4,int v5)
{
double sum = v1;
if(val >= 2)
sum += v2;
if(val >= 3)
sum += v3;
if(val >= 4)
sum += v4;
if(val >= 5)
sum += v5;
return sum/val;
}
int main ()
{
printf("%f\n",average(5,1,3,5,6,7));
return 0;
}
#include <stdio.h>
#include <stdarg.h>
double average(int val, ...)
{
int i = 0;
va_list arg;
double sum = 0.0;
va_start(arg, val);
for (i = 0; i < val; i++)
{
sum += va_arg(arg, int);
}
va_end(arg);
return sum / val;
}
int main()
{
double ret = average(6,1,2,3,4,5,8);
printf("%f\n", ret);
return 0;
}
标签:
原文地址:http://blog.csdn.net/sulijuan66/article/details/45651703