/** * avetesta.c - An interactive test of the average procedure. */ #include #include #include "average.h" #define MAX_VALUES 64 int min (int x, int y) { return x < y ? x : y; } // min int main (int argc, char **argv) { int values[MAX_VALUES]; int count = min (argc-1, MAX_VALUES); int i; // Sanity check if (argc == 1) { printf ("Usage: %s val1 val2 val3 ... valn\n", argv[0]); return EXIT_FAILURE; } // Warning if (argc > MAX_VALUES) printf ("Only using the first %d values.\n", MAX_VALUES); // Fill in the values array for (i = 0; i < count; i++) values[i] = atoi (argv[i+1]); // Compute the average printf ("The average is %d.\n", average (values, count)); // And we're done return EXIT_SUCCESS; } // main