fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main ()
  8. {
  9. int n; cin >> n;
  10. vector<double> v(n);
  11. for (auto &x : v) cin >> x;
  12. cout << "min by absolute is ";
  13. cout << *min_element( begin(v), end(v), [](double a, double b){
  14. return abs(a) < abs(b); } );
  15. return 0;
  16. }
  17.  
Success #stdin #stdout 0s 3032KB
stdin
5
-1 -5 9 6 2
stdout
min by absolute is -1