# Largest of two distinct numbers without using any conditional statements or operators

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).

**Examples:**

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.

## C++

`// C++ program for above implementation ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// Function to find the largest number ` `int` `largestNum(` `int` `a, ` `int` `b) ` `{ ` ` ` `return` `a * (` `bool` `)(a / b) + b * (` `bool` `)(b / a); ` `} ` ` ` `// Drivers code ` `int` `main() ` `{ ` ` ` `int` `a = 22, b = 1231; ` ` ` `cout << largestNum(a, b); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## PHP

**Output:**

1231

## Recommended Posts:

- Numbers less than N which are product of exactly two distinct prime numbers
- Maximum sum of distinct numbers such that LCM of these numbers is N
- Add two numbers without using arithmetic operators
- Maximum sum of distinct numbers with LCM as N
- Numbers having Unique (or Distinct) digits
- Exactly n distinct prime factor numbers from a to b
- Russian Peasant (Multiply two numbers using bitwise operators)
- Check if all sub-numbers have distinct Digit product
- Find two distinct prime numbers with given product
- Number of distinct prime factors of first n natural numbers
- Largest Even and Odd N-digit numbers
- Largest number in [2, 3, .. n] which is co-prime with numbers in [2, 3, .. m]
- Largest palindrome which is product of two n-digit numbers
- C program to Find the Largest Number Among Three Numbers
- Largest N digit number divisible by given three numbers

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.