Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Hide Buttons

Sort 3 Integers without using if condition OR use only Max() function.

Objec­tive: Given three integers, sort them without using if condition.

Appraoch:

  • Say 3 integers are, a, b, c.
  • Find the maximum of a, b, c using Max() function.
  • multiply all integers by -1. Again find Minimum of -a, -b, -c using Max() function.
  • Add the Max and Min from above steps and subtract it from (a+b+c). It will give you middle element.

Complete Code:

Output:

Sorted order 1 4 9

__________________________________________________
Top Companies Interview Questions..-

Google Microsoft Amazon Facebook more..

If you find anything incorrect or you feel that there is any better approach to solve the above problem, please write comment.
__________________________________________________

You may also like...

%d bloggers like this: