Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Pinterest
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

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

Objec­tive: - Given three inte­gers, sort them with­out using if condition.

Appraoch:

  • Say 3 inte­gers are, a, b, c.
  • Find the max­i­mum of a, b, c using Max() function.
  • mul­ti­ply all inte­gers by –1. Again find Min­i­mum of –a, –b, –c using Max() function.
  • Add the Max and Min from above steps and sub­tract it from (a+b+c). It will give you mid­dle element.

Com­plete Code:

Out­put:

Sorted order 1 4 9

You may also like...