urparvezali's blog

By urparvezali, history, 17 months ago, In English

If you need to determine minimum and maximum in C++ from a certain value or variable then you can try it

int maxNum = max({a,b,c});
int minNum = min({a,b,c});
or
int maxNum = max({n1,n2,n3,n4....nn});
int minNum = min({n1,n2,n3,n4....nn});

where a,b,c and n1,n2,n3...nn are variables or values

  • Vote: I like it
  • +24
  • Vote: I do not like it

| Write comment?
»
17 months ago, # |
  Vote: I like it +30 Vote: I do not like it

Don't use variable name as builtin functions

»
17 months ago, # |
  Vote: I like it +3 Vote: I do not like it

This is std::initializer_list.

»
11 months ago, # |
  Vote: I like it -11 Vote: I do not like it

I was using smth like max(x1,max(x2,max(x3,x4)))

»
11 months ago, # |
Rev. 3   Vote: I like it +3 Vote: I do not like it

Also try this method for max and min value.

//using vector
int max_value = *max_element(array.begin(), array.end());
int min_value = *min_element(array.begin(), array.end());