/* testarr09.cpp CIS 150 06/23/2005 David Klick This program shows how some of the common array tasks can be performed using functions. */ #include #include #include #include using std::cout; using std::setw; const int ARRAY_SIZE = 10; void initialize(int a[], int length); void display(int a[], int length); int sum(int a[], int length); double average(int a[], int length); int min(int a[], int length); int max(int a[], int length); int main(void) { int nums[ARRAY_SIZE]; // seed the random number generator srand(time(NULL)); // initialize the array to random numbers initialize(nums, ARRAY_SIZE); // display the array on one line display(nums, ARRAY_SIZE); // add up all the array elements cout << "The sum is " << sum(nums, ARRAY_SIZE) << '\n'; // calculate and display the average cout << "The average is " << average(nums, ARRAY_SIZE) << '\n'; // find the minimum value cout << "The smallest value is " << min(nums, ARRAY_SIZE) << '\n'; // find the maximum value cout << "The largest value is " << max(nums, ARRAY_SIZE) << '\n'; return 0; } void initialize(int a[], int length) { for (int i=0; i maxval) maxval = a[i]; } return maxval; }