fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <climits>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. int numbers[] = { 2, 3, 1, 4, 5, 6, 4, 3, 5, 7 };
  9. int min_number = INT_MAX, max_number = INT_MIN;
  10. for_each(begin(numbers), end(numbers),
  11. [&min_number, &max_number](int n) {
  12. min_number = min(min_number, n);
  13. max_number = max(max_number, n);
  14. });
  15. cout << "MAX: " << max_number << "\nMIN: " << min_number << endl;
  16. return 0;
  17. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
MAX: 7
MIN: 1