The most idiomatic way would be to use std::max_element which does exactly what the name suggests. For that, values would need to be in a container, for which e.g. a brace-initialized std::array
(for a known number of 5 values), or a std::vector
(for unknown-number of values) will do.
The next best way would be sorting as suggested by @Dilusha, but of course there's partial sorting and std::nth_element
, which will do less work for the same net result (as you do not really need a sorted sequence, you only need one element in the right place -- a complete sort is thus "wasteful").
Or, you can of course just use a sequence of result = std::max(result, a [b c d... whatever])
which isn't very elegant, but will do the job just fine. Remember to initialize result
to zero to begin with.