106k views
3 votes
rite a complete function (DO NOT WRITE A COMPLETE PROGRAM: prototypes, no includes, no main, no input, no output) named average that takes two arguments as described below and returns a double:•the first argument, named scores, is a one-dimension array of doubles, that are test scores•the second argument, named size, is an int that is the number of elements in the scores array•the return value is the average or mean of all of the test scores

User Dest
by
4.9k points

1 Answer

7 votes

Answer:

double average(double* scores, int size)

{ double sum = 0;

for (int i = 0; i < size; i++)

sum += scores[i];

return sum / size; }

Step-by-step explanation:

Above is the function defined and its explanation is as follows:

double average(double* scores, int size)

  • A variable average with data type double having two arguments scores(array of doubles having scores) and size(number of elements of array scores).

double sum = 0;

for (int i = 0; i < size; i++)

sum += scores[i];

  • All the scores in the array are added into a variable named sum with data type double.

return sum / size;

  • Return value will give the average of all the scores calculated by dividing sum of all the scores with size(total number) of scores.
User Halim
by
5.1k points