// Find minimum and maximum of a series of numbers. Uses vectors. // Michael Rothstein // 4/7/2014 #include #include const int STOP_AT=0; using std::cin; using std::cout; using std::endl; using std::vector; void minmax(vector v,int &low,int &high); int main(){ vector a; // Read in the numbers... cout << "Input numbers, end input with " << STOP_AT << endl; int num; cin >> num; while (num !=STOP_AT ){ a.push_back(num); cin >> num; } int min,max; minmax(a,min,max); cout << "The smallest number is " << min << " and the largest is " << max << endl; } void minmax(vector v,int &low,int &high){ low = high = v[0]; for(vector::iterator ip=v.begin()+1;ip < v.end(); ip++){ if ( *ip < low ) low = *ip; if ( *ip > high) high = *ip; } }