Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

minimum and maximum value of a vector in C++

#include <iostream>
#include <vector>
#include <algorithm>
 
int main()
{
    std::vector<int> v = {2, 1, 3, 6, 7, 9, 8};
 
    int max = *max_element(v.begin(), v.end());
    int min = *min_element(v.begin(), v.end());
 
    std::cout << min << ", " << max << std::endl;        // 1, 9
 
    return 0;
}
Source by www.techiedelight.com #
 
PREVIOUS NEXT
Tagged: #minimum #maximum #vector
ADD COMMENT
Topic
Name
8+1 =