#include #include #include #include #include // preferred method for defining array size: #define MAXDICE 1000000 void Roll(int* array_, int size_); int Stat(int* array_, int size_, double* average_, double* empdev_); int main(void) { int *dice; // array to store dice rolls double av; // average double dev; // standard deviation (estimation of) // Homework: what is the exact value? // memory allocation for the array 'dice': dice = (int*)calloc(MAXDICE, sizeof(int)); if (!dice) { fprintf(stderr, "Not enough memory or memory error... Exit...\n"); return 0; } srand(time(0)); // initialize with system time (not the best) // generate data: Roll(dice, MAXDICE); // call the statistics function: if (Stat(dice, MAXDICE, &av, &dev)) { printf("%lf +/- %lf\n", av, dev); } else { fprintf(stderr, "Stat function failed. Return 0...\n"); free(dice); return 0; } free(dice); return 1; } // ********** end of main ************** void Roll(int* array_, int size_) { int i; for (i=0; i 6) ) { fprintf(stderr, "Invalid data: array_[%d]=%d... Return 0...\n", i, array_[i]); return 0; // something went wrong } } // calculate average: avrg = 0; for (i=0; i