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

Examples:

```Input : 4 8 6 5
Output : 8

Input : 11 17 8 17
Output : 17
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

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.

 `// CPP program to find maximum of 4 numbers ` `// without using conditional and bitwise ` `// operators. ` `#include ` `using` `namespace` `std; ` ` `  `int` `maxOfFour(``int` `w, ``int` `x, ``int` `y, ``int` `z) ` `{ ` `    ``int` `a; ` `    ``a = w, a = x; ` ` `  `    ``// b is 0 if w is less than or equal ` `    ``// to x, else it is non-zero. ` `    ``bool` `b = (a - a + ``abs``(a - a)); ` ` `  `    ``// After below operation, a is maximum ` `    ``// of w and x. ` `    ``swap(a, a[!b]); ` ` `  `    ``// After below three steps, a is maximum ` `    ``// of w, x and y. ` `    ``a = y; ` `    ``b = (a - a + ``abs``(a - a)); ` `    ``swap(a, a[!b]); ` ` `  `    ``// After below three steps, a is maximum ` `    ``// of w, x, y and z. ` `    ``a = z; ` `    ``b = (a - a + ``abs``(a - a)); ` `    ``swap(a, a[!b]); ` ` `  `    ``return` `a; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``int` `w = 12, x = 15, y = 18, z = 17; ` `    ``cout << ``"Maximum of four : "` `         ``<< maxOfFour(w, x, y, z); ` `    ``return` `0; ` `} `

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 contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.