#include #include using namespace std; // In the prototype of a function that is passed an array, we include the // name of the array with empty brackets. This is a pointer to the array. // It would also work if we used float *x. float max_element( float x[], int n ) { float max_el = x[0]; for ( int i = 1; i < n; i++ ) { if ( x[i] > max_el ) max_el = x[i]; } return( max_el ); } int main() { float y[10] = { 1.3, 13.9, -7.2, 8.8, 9.12, -0.34, 1.2, 8 }; // Recall that y[8] and y[9] are automatically assigned zero values. float x = max_element( y, 10 ); // y is the base address of the array cout << "The max element of the array is " << x << "\n\n"; x = max_element( &y[0], 10 ); // Same as above cout << "The max element of the array is " << x << "\n\n"; x = max_element( &y[5], 5 ); // Starts at 5th element and checks 5 elements cout << "The max element of the last half of the array is " << x << endl; cout << "\n\n"; system( "PAUSE" ); return( EXIT_SUCCESS ); }