// Find the minimum and maximum values in a dynamically allocated array. // Michael Rothstein // 2/12/14 ammended 3/31/14, 7/17/14 #include using std::cin; using std::cout; using std::endl; void minmax(const int a[],int n,int &min,int &max); int main(){ int *data; cout << "How many items are there? "; int n; cin >> n; data = new int[n]; if ( data == NULL ){ cout << "Sorry, could not allocate array!\n"; return 1; } cout << "Please enter the numbers, one by one.\n"; for(int i=0;i> data[i]; } int min,max; minmax(data,n,min,max); cout << "The smallest number is " << min << " and the largest is " << max << endl; } void minmax(const int a[],int n, int&min, int&max){ min = max = a[0]; for(int i=1;i max) max = a[i]; } }