/* ptrtest2.c Use AS-IS to test CS 60 assignment 2, part 2b, Fall 2009 updated by cmc, 10/6/09 */ #include #include #include #include "ptrfuncs.h" int main(int argc, char *argv[]) { double x[] = { 406.94, 198.63, 961.99, 238.36, 910.21, 188.81, 467.37, 639.6, 125.1, 581.16, 144.5, 354.07, 812.45, 716.26, 150.35, 753.4, 387.7, 491.69, 788.64, 624.17, 263.02, 545.16, 908.81, 829.42, 620.95, 684.85, 479.14, 210.61, 685.58, 23.42, 466.19, 641.73, 985.22, 803.12, 139.89, 106.97, 463.64, 575.13, 461.76, 572.48 }; int nx = (sizeof x) / sizeof(double); double *p; unsigned seed; srand(time(NULL)); /* system time used for random seed by default */ if (argc > 1 && sscanf(argv[1], "%u", &seed) > 0) srand(seed); /* change the seed if one is input by the user */ puts("first 25 values of x, 7 per line:"); printTable(x, 25, 7); puts("last 20 values of x, 4 per line:"); printTable(x + nx - 20, 20, 4); puts("25 random values in range -20 to +20:"); p = randomValues(25, -20, 20); printTable(p, 25, 5); free(p); /* good practice to avoid memory leak */ puts("10 random values in range -200 to +200:"); p = randomValues(10, -200, 200); printTable(p, 10, 5); free(p); puts("40 random values in range 0 to 1000:"); p = randomValues(40, 0, 1000); printTable(p, 40, 5); free(p); return 0; }