Explanation:
#include <cstdarg>
#include <iostream>
using namespace std;
double average ( int cnt, ... )
{
va_list arg_avg;
double sum_no = 0;
va_start ( arg_avg, cnt );
for ( int x = 0; x < cnt; x++ )
{
sum_no += va_arg ( arg_avg, int ); // Adds the next value in argument list to sum.
}
va_end ( arg_avg );
return sum_no / cnt;
}
int main()
{
cout<< average ( 2, 12,13 ) <<endl;
}
Here va_list can declare variables which can hold variable number of values. va_start to initialize and va_end to clean up the list.