Given three integers, print them in sorted order without using if condition.
Input : a = 3, b = 2, c = 9 Output : 2 3 9 Input : a = 4, b = 1, c = 9 Output : 1 4 9
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.
It works for negative numbers also.
1 4 9
This article is contributed by Rakesh Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Comparison among Bubble Sort, Selection Sort and Insertion Sort
- Minimum product of k integers in an array of positive Integers
- Sort an almost sorted array where only two elements are swapped
- Number of swaps to sort when only adjacent swapping allowed
- Sort an array with swapping only with a special element is allowed
- Sort only non-prime numbers of an array in increasing order
- Sort integers in array according to their distance from the element K
- Program to sort an array of strings using Selection Sort
- Odd Even Transposition Sort / Brick Sort using pthreads
- Sort an Array which contain 1 to N values in O(N) using Cycle Sort
- Sort an array without changing position of negative numbers
- Why Quick Sort preferred for Arrays and Merge Sort for Linked Lists?
- Odd-Even Sort / Brick Sort
- Bucket Sort To Sort an Array with Negative Numbers
- Sort all even numbers in ascending order and then sort all odd numbers in descending order
- Serial Sort v/s Parallel Sort in Java
- C/C++ Program for Odd-Even Sort / Brick Sort
- Java Program for Odd-Even Sort / Brick Sort
- Insertion sort to sort even and odd positioned elements in different orders
- Quick Sort vs Merge Sort
Improved By : nitin mittal