/* ptrtest1.c Use AS-IS to test CS 60 assignment 2, part 2a, Fall 2009 updated by cmc, 10/6/09 */ #include #include "ptrfuncs.h" int main(void) { 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, 287.31, 913.75, 811, 245.32, 997.68, 701.87, 806.56, 76.68, 368.48, 792.79, 645.42, 868.44, 87.5, 702.63, 403.33, 698.98, 772.66, 793.88, 678.93, 37.28, 328.28, 893.33, 80.62, 721.98, 213.74, 251.96, 375.7, 18.64, 541.57, 117.97, 315.98, 136.18, 743.54, 519.56, 863.66, 359.53, 340.57, 283.71, 908.8, 600.22, 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); /* total number of values */ int half = nx / 2; double *first = x; double *max, *min; puts("results for whole set of values:"); printf(" sum = %.2f\n", sum(first, nx)); max = maxPtr(first, nx); printf(" max = %.2f, at position %d\n", *max, max - first); min = minPtr(first, nx); printf(" min = %.2f, at position %d\n", *min, min - first); printf(" range = %.2f\n", valueDiff(max, min)); puts("results for first half of values:"); printf(" sum = %.2f\n", sum(first, half)); max = maxPtr(first, half); printf(" max = %.2f, at position %d\n", *max, max - first); min = minPtr(first, half); printf(" min = %.2f, at position %d\n", *min, min - first); printf(" range = %.2f\n", valueDiff(max, min)); puts("results for second half of values:"); printf(" sum = %.2f\n", sum(first + half, half)); max = maxPtr(first + half, half); printf(" max = %.2f, at position %d\n", *max, max - first); min = minPtr(first + half, half); printf(" min = %.2f, at position %d\n", *min, min - first); printf(" range = %.2f\n", valueDiff(max, min)); return 0; }