void fill_1d_all(int array[], int low, int high) { int i; for (i = low; i <= high; i++) get_int(&array[i]); } void fill_1d_part(int array[], int low, int high, int *actual) { int i = low, temp; do { printf("\nEnter a value >= 0 or -1 to quit "); scanf("%d", &temp); if (temp >= 0) { array[i] = temp; i = i + 1; } } while ((i <= high) && (temp >= 0)); *actual = i - 1; if (i > high) printf("\nArray is full, no more values can be added "); } void print_1d(int array[], int low, int high) { int i; printf("\n\n"); for (i = low; i <= high; i++) printf("%d ", array[i]); } int find_small(int array[], int low, int high) { int small, index; small = array[low]; for (index = low + 1; index <= high; index++) { if (array[index] < small) small = array[index]; } return small; } int find_large(int array[], int low, int high) { int large, index; large = array[low]; for (index = low + 1; index <= high; index++) { if (array[index] > large) large = array[index]; } return large; } int find_value_location(int array[], int low, int high, int value) { int location, found, index; location = low - 1; found = 0; /*0 stands for false in C*/ index = low; while ((index <= high) && (found == 0)) { if (array[index] == value) { location = index; found = 1; } index = index + 1; } return location; } /* binary search of an array to find a location. Array must be in ascending order. */ int binary_search(int array[], int low, int high, int value) { int middle = (high - low)/2; int location; if (low == high) middle = low; else middle = (high - low)/2; if (low > high) location = -1; else if (value < array[middle]) location = binary_search(array, low, middle - 1, value); else if (value > array[middle]) location = binary_search(array, middle + 1, high, value); else location = middle; return(location); } int find_small_location(int array[], int low, int high) { int small, index, location; small = array[low]; location = low; for (index = low + 1; index <= high; index++) { if (array[index] < small) { small = array[index]; location = index; } } return location; } int find_large_location(int array[], int low, int high) { int large, index, location; large = array[low]; location = low; for (index = low + 1; index <= high; index++) { if (array[index] > large) { large = array[index]; location = index; } } return location; } int sum_1d(int array[], int low, int high) { int i, sum = 0; for (i = low; i <= high; i++) sum = sum + array[i]; return (sum); } double find_average(int array[], int low, int high) { int i, count = 0; double sum = 0.0; for (i = low; i <= high; i++) { sum = sum + array[i]; count++; } return (sum/count); }