Arrays are passed by reference (address) by default.

Function takes an array and tries to return average, sum of elements, and the sum of the squares.

Calculate and display sum, sumsq using for loop in the function definition display sum, avg, and sumsq to see the difference between the values inside and outside function. If you see any difference explain why?

This is what I have:

``````void stats(double a[], int n, double & avg, double & sum, double & sumsq)
{
int i;
avg = 0.;
sum = 0.;
sumsq = 0.;
//how to calculate and display sum, sumsq using for loop in the function definition?
}

void main() {
double a[3] = {1, 3, 5};
double avg = 0, sum = 0, sumsq = 0;

stats(a, 3, avg, sum, sumsq);

//how to display sum, avg, and sumsq to see the difference between the values inside and outside function?

}``````

Line 7 - a[] and n are your inputs. How do you do you calculate average, sum, and sum squared on paper? Do it the exact same way here. You need a loop and the loop parameter is going to have something to do with n. Within that loop you're going to have to isolate individual elements of a[] and do something with them mathematically.