Mega Code Archive

 
Categories / C++ Tutorial / STL Algorithms Min Max
 

Use max_element to get the maximum value

#include <algorithm> #include <functional> #include <iomanip> #include <iostream> #include <vector> using namespace std; int main(){    const float a[] = { 13.4, 27.6, 15.5, 44.3, 51.2, 30.2, 18.0 };    vector<float> data( a,a + sizeof( a ) / sizeof( a[0] ) );    float data_min = *min_element( data.begin(), data.end() );    float data_max = *max_element( data.begin(), data.end() );    cout << data_max; }