Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine the largest number among three numbers using C++

Tags:

c++

How can I determine the largest number among three numbers using C++?

I need to simplify this

 w=(z>((x>y)?x:y)?z:((x>y)?x:y));

Conditionals do not simplify this.

like image 881
trafalgarLaww Avatar asked Nov 27 '22 08:11

trafalgarLaww


2 Answers

Starting from C++11, you can do

w = std::max({ x, y, z });
like image 113
oisyn Avatar answered Dec 21 '22 07:12

oisyn


w = std::max(std::max(x, y), z);

is one way.

like image 38
Bathsheba Avatar answered Dec 21 '22 07:12

Bathsheba