Sort 3 Integers without using if condition or using only max() function - GeeksforGeeks
Given three integers, print them in sorted order without using if condition.
1. Find the maximum of a, b, c using max() function.
3. Multiply all integers by –1. Again find Minimum of –a, –b, –c using max() function.
4. Add the Max and Min from above steps and subtract the sum from (a+b+c). It gives us middle element.
Read full article from Sort 3 Integers without using if condition or using only max() function - GeeksforGeeks
Given three integers, print them in sorted order without using if condition.
1. Find the maximum of a, b, c using max() function.
3. Multiply all integers by –1. Again find Minimum of –a, –b, –c using max() function.
4. Add the Max and Min from above steps and subtract the sum from (a+b+c). It gives us middle element.
void
printSorted(
int
a,
int
b,
int
c)
{
// Find maximum element
int
get_max = max(a, max(b, c));
// Find minimum element
int
get_min = -max(-a, max(-b, -c));
int
get_mid = (a+b+c) - (get_max+get_min);
cout << get_min <<
" "
<< get_mid
<<
" "
<< get_max;
}