## $Id: s3-quiz.html,v 1.4 1996/10/04 21:55:27 ellard2 Exp ellard2 $ ## Dan Ellard - Review Problems
/* The length of all the arrays is */ /* always ARRAY_LENGTH. */ #define ARRAY_LENGTH 129 /* The different ways that an array can */ /* be sorted. Note that these values */ /* may appear to be chosen at random- */ /* they were. */ #define ASCENDING 102 #define DESCENDING 93 #define UNSORTED 8
Write array_get, a function that reads in ARRAY_LENGTH integers from the user and places them into the given array array. Feel free to use GetInteger.
Write array_min, a function that returns the minimum (smallest) value in the array.
Write array_min_index, that is like array_min, except that it returns the index in array occupied by the smallest element.
Write array_max, a function that returns the maximum (largest) value in the array.
Write array_max_index. This function is similar to array_max, except that it returns the index in array occupied by the largest element instead of the value of the largest element.
Write array_max_abs, a function that returns the value of the element with the largest absolute value in the array. (Hint- you may assume that array_min and array_max have already been written. You may find them useful.)
Write array_min_abs, a function that returns the element with the smallest absolute value in the array. (Like for the previous problem, you may assume that array_min and array_max have already been written- but in this case they are not nearly so useful.)
Write array_sum, a function that returns the sum of all the elements in array.
Write array_product, a function that returns the product of all of the elements in array.
Write array_average, a function that returns the average value of the elements in array (as an integer).
Write array_sorted_ascending, a function that returns TRUE if array is sorted in ascending order (each number <= the next), FALSE otherwise.
Write array_sorted_descending, a function that returns TRUE if array is sorted in descending order (each number >= the next), FALSE otherwise.
Write array_sorted, a function that returns ASCENDING if array is sorted in ascending order, DESCENDING if array is sorted in descending order, or UNSORTED if array is not sorted. If all of the elements of the array have the same value, then this function should return ASCENDING.
Write array_print, a function that prints the contents of the array. Make the output easy to read.
Write array_larger, a function that returns TRUE if every element in a1 is larger than every element in a2. (Hint- there's a hard way and an easy way to do this. The easy way is very easy, and uses some of the functions mentioned previously.)
Write a function that prints out every number from min to max (including both min and max) that is evenly divisible by factor. You may assume that min, max, and factor have already been defined and are integers. You may assume that factor is not zero, although you may not assume that it is positive.
Write a function print_number that prints out any integer greater than zero and less than 1000 in "words", so that the number 123 would be printed as "one two three", and 47 would be printed as "four seven".
Do this three ways: first using an array, then another using switch, and finally using a cascaded if statement. What is good or bad about each of these approaches?