Answer:
Following are the definition of function
double averager (const double &x) // function definition
{
static double z = 0.0; // variable declaration
static size_t c = 0;
c=c+1; // increment of c by 1
z =z+ x; // adding value
return z /c ; // return average
}
Explanation:
Following are the description of statement
- Create a function averager of double type that holds a parameter "x" of the double type .
- In this function we declared a variable "z" of a static double type that value is initialized by 0.
- The static variable is used to retain value.
- Declared a variable "c" of size_t type that holds a value 0 .
- After that increment the value of c by 1 .
- adding the value of "z" variable to the "x" and storing the result into the z variable.
- Finally return the average value