Example
[c]
#include<stdio.h>
#include<conio.h>
#include<stdarg.h>
int average(int cnt,...)
{
int sum=0,i;
va_list lst;
va_start(lst,cnt);
for(i=0; i<cnt; i++)
{
int n=va_arg(lst,int);
sum+=n;
}
va_end(lst);
return sum;
}
int main()
{
printf("average of 4,1,2,3,4 = %d\n",average(4,1,2,3,4));
printf("average of 3,1,2,3 = %d\n",average(3,1,2,3));
printf("average of 7,1,2,3,4,5,6,7 = %d\n",average(7,1,2,3,4,5,6,7));
printf("average of 2,1,2 = %d\n",average(2,1,2));
return 0;
}[/c]
Output:
[c]
average of 4,1,2,3,4 = 10
average of 3,1,2,3 = 6
average of 7,1,2,3,4,5,6,7 = 28
average of 2,1,2 = 3
[/c]