// This is a version of a program we wrote last week. Except this one, I have // filled with bugs, so we can have a look at how we can find them. This program // will not compile until we fix these bugs // The original program allows a user to input ten positive numbers and then // finds the either the largest or the smallest of these based on user request // Sasha Vassar Week 5, Lecture 9 // Problem: A user is asked to enter 10 positive numbers. The user is then asked // if they want the highest or the lowest number of these. #include int smallest(int numbers[10]); int highest(int numbers[10]); int main (void) { int numbers[10] = {0}; int i = 0; while (i < 10) { printf("Please enter a number: "); scanf("%d", &numbers[i]); i++; } printf("Would you like to find the smallest of these or the largest S/L: "); char command; scanf(" %c", &command); if (command == 'L') { printf("The highest number is: %d\n", highest(numbers)); } else if (command == 'S') { printf("The smallest number is: %d\n", smallest(numbers)); } return 0; } // Function finds the highest number in an arrays int highest(int numbers[10]) { int highest_number = -1; int i = 0; while (i < 10) { if (numbers[i] > highest_number) { highest_number = numbers[i]; } i++; } return highest_number; } // Function finds the smallest number in an arrays int smallest(int numbers[10]) { int smallest_number = numbers[0]; //printf("Debugging smallest number is = %d\n", smallest_number); int i = 1; while (i < 10) { if (numbers[i] < smallest_number) { smallest_number = numbers[i]; } i++; } return smallest_number; }