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 firstname.lastname@example.org. 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.
- Implementing ternary operator without any conditional statement
- Why overriding both the global new operator and the class-specific operator is not ambiguous?
- Largest in array without using conditionals / bitwise / ternary operators
- Find maximum in an array without using Relational Operators
- Android | App to Add Two Numbers
- How will you print numbers from 1 to 100 without using loop? | Set-2
- How will you print numbers from 1 to 100 without using loop?
- Fill 8 numbers in grid with given conditions
- Why are negative numbers stored as 2's complement?
- New Algorithm to Generate Prime Numbers from 1 to Nth Number
- Find if a molecule can be formed from 3 atoms using their valence numbers
- Reduce the number to minimum multiple of 4 after removing the digits
- Transportation Problem | Set 7 ( Degeneracy in Transportation Problem )
- Transportation Problem | Set 6 (MODI Method - UV Method)