Write a program named Averagesthat includes a method named Average that accepts any number of numeric parameters, displays them, and displays their average.

For example, if 7 and 4 were passed to the method, the ouput would be:

7 4 -- Average is 5.5
Test your function in your Main(). Tests will be run against Average()to determine that it works correctly when passed one, two, or three numbers, or an array of numbers.

Respuesta :

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.