Input: arr[] = { 8.33, -3.85, 1.999, 6.33, 5}
Output: { 1.999, 8.33, 6.33, -3.85 , 5}
Explanation:
Element | Integer Value | Fraction Value |
8.33
| 8
| 0.33
|
-3.85
| -4
| 0.15
|
1.999
| 1
| 0.999
|
6.33
| 6
| 0.33
|
5
| 5
| 0.0
|
1.999 has the biggest fractional value so it will be at index 0 while 5 has the lowest fractional value so it will be at the last index.
6.33 and 8.33 have the same fractional values but the Integer part of 8.33 is greater than 6.33 so we place 8.33 before 6.33 as the given condition in the problem statement.
Fractional value = Given number - Integer Value.
Fractional Value of positive value e.g. (8.33) = 8.33 - Integer Value of ( 8.33)= 8.33 - 8= 0.33
Fractional Value of (-3.85) = -3.85- Integer Value of (-3.85)= -3.85 - ( -4 ) = -3.85 + 4 = 0.15
Hence, the order for the above example will be: {1.999, 8.33, 6.33, -3.85, 5}
Input: arr[] = { 1.1, 1.11, 1.111, 2.1, 2.11, 2.111}
Output: { 2.111, 1.111, 2.11, 1.11, 2.1, 1.1 }
Explanation: Here the biggest fractional value is 0.111 which is present in both 2.111 and 1.111. But the integer value of 2.111 is greater than 1.111. so, 2.111 will come before 1.111. The same applies to other elements.