Mathematics 1201: Programming in C Solutions to Homework Assignment #7 Prof. Wickerhauser Exercise 4, Chapter 7, p. 178. Program: #include #define MaxDegree 100 typedef double Polynomial[ MaxDegree ]; /* degree 99 or less */ void Add ( Polynomial Left, Polynomial Right, Polynomial Sum ) { int i; for( i=0; i void PrintArray( int *A, unsigned int N, const char *Name ) { int i; printf("%s =", Name); for ( i=0; i #include #define LENGTH (1<<20) /* big, i.e., 1<<20 */ void usage(char *program_name) { printf("Usage: %s x; x=1 for Max1() and x=2 for Max2().\n", program_name); exit(1); } int main(int argc, char **argv) { int i, max, *a; if(argc!=2) usage(argv[0]); /* Allocate `a[]' and fill it with a few numbers: */ a = (int *)calloc(LENGTH, sizeof(int)); switch( *argv[1] ) { case '1': max = Max1(a,LENGTH); break; case '2': max = Max2(a,LENGTH); break; default: usage(argv[0]); } printf("Max%c: %d\n", *argv[1], max); return(0); } Output: Optimized: % cc -O ch7ex17.c % time a.out 2 ==> 0.6 seconds % time a.out 1 ==> 0.6 seconds Not optimized: % cc ch7ex17.c % time a.out 1 ==> 1.3 seconds % time a.out 2 ==> 0.9 seconds