Just Average

Among the tools missing from the C library, which are ample in other programming languages, are functions that manipulate arrays. I’ve seen functions in other programming languages that slice, dice, mince, and chop an array. One of the more common functions calculates the average of a numeric array.

For example, some other programming language may have an average() function. You send the function an array — or raw values — and it spews back the average of all the numbers. And that just happens to be your Exercise for the month of January, 2015.

Happy New Year!

The following code skeleton contains the array you need to average. It also contains other information you can use to concoct your own average() function.

#include <stdio.h>

#define COUNT 10

int main()
{
    float scores[COUNT] = {
        97.2, 86.0, 75.5, 93.2, 87.1,
        68.7, 81.9, 92.4, 84.0, 66.3 };
    int x;

    for(x=0;x<COUNT;x++)
        printf("Student %2d score %3.1f\n",x+1,scores[x]);
    /* display average score */

    return(0);
}

average()
{
}

Your task is to create the average() function, supply its arguments (important), and stick that function in the appropriate spot in the main() function.

Click here to read about my solution, although I strongly encourage you to first try this Exercise on your own.