![]() |
VOOZH | about |
Given four numbers, print the maximum of the 4 entered numbers without using conditional or bitwise operator (not even ternary operators). Examples:
Input : 4 8 6 5
Output : 8
Input : 11 17 8 17
Output : 17
We use the fact that value of "(x - y + abs(x - y))" will be 0 of x is less than or equal to y. We use this value as index in an array of size 2 to pick maximum. Once we have found maximum of two elements, we can use same technique for finding maximum of all.
Output:
Maximum of four : 18
This article is contributed by
Arkajyoti Banerjee. If you like GeeksforGeeks and would like to contribute, you can also write an article using
write.geeksforgeeks.orgor mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.