#include <stdio.h>
#include <stdarg.h>
float average(int val, ...)
{
va_list a; //定义可变参数
int count;
float sum = 0;
va_start(a, val);//准备访问可变参数
for (count = 0; count < val; count++)//添加可变参数列表中的值参数
{sum += va_arg(a, int);}va_end(a);//完成处理可变参数return sum / val;
}
<pre class="cpp" name="code" snippet_file_name="blog_20150404_1_9148109" code_snippet_id="636153">int main()
{
printf("%f\n",average(4,2,3,5,6,7));
return 0;}
}
<img width="671" height="268" style="width: 671px; height: 257px;" src="http://img.blog.csdn.net/20150404222300083?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveWFuZ3NodWFuZ3Rhbw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />