Maximum of four numbers without using conditional or bitwise operator
Given four numbers, print the maximum of the 4 entered numbers without using conditional or bitwise operator (not even ternary operators).
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.
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 contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.