Given two positive and distinct numbers, the task is to find the greatest of two given numbers without using any conditional statements(if…) and operators(?: in C/C++/Java).
Input: a = 14, b = 15 Output: 15 Input: a = 1233133, b = 124 Output: 1233133
The Approach is to return the value on the basis of the below expression:
a * (bool)(a / b) + b * (bool)(b / a)
The expression a / b will give 1 if a > b and 0 if a < b (only after typecasting the result to bool).
Hence, the answer will be of the form either a + 0 or 0 + b depending upon which one is greater.