|
|
|
Chapter 11Answers to Selected Exercises
2. [was #2] (e), (f), and (i) are legal. (a) is illegal because 4. [was #4; modified] void swap(int *p, int *q) { int temp; temp = *p; *p = *q; *q = temp; } 6. [was #6] void find_two_largest(int a[], int n, int *largest, int *second_largest) { int i; if (a[0] > a[1]) { *largest = a[0]; *second_largest = a[1]; } else { *largest = a[1]; *second_largest = a[0]; } for (i = 2; i < n; i++) if (a[i] > *largest) { *second_largest = *largest; *largest = a[i]; } else if (a[i] > *second_largest) *second_largest = a[i]; } Copyright © 2008, 1996 W. W. Norton & Company, Inc. All rights reserved. |