/* Represent distances to cities near Irvine using an array Emad Arasteh November 7, 2019 */ #include int find_min(int d[]); int find_max(int d[]); int find_min(int d[]) { int min = d[0]; int i; for (i = 1; i < 8; i++) { if (d[i] < min) { min = d[i]; } } return min; } int find_max(int d[]) { int max = d[7]; int i; for (i = 0; i < 7; i++) { if (d[i] > max) { max = d[i]; } } return max; } int main() { /* Initialize one-dimensional array of distances from Irvine to Long Beach, Los Angeles, Fullerton, Pomana, Rancho Cucamonga Riverside, Rancho Santa Margarita, Laguna Niguel */ int distances[8] = {22, 35, 14, 25, 32, 30, 13, 12}; int index; int closest, farthest; for (index = 0; index < 8; index++) { printf("distances[%0d]: %0d miles \n", index, distances[index]); } closest = find_min(distances); farthest = find_max(distances); printf("The closest city to Irvine has a distance of %0d miles. \n", closest); printf("The farthest city from Irvine has a distance of %0d miles. \n", farthest); return 0; }