How to round off a float to int value in c?
Answers
Answered by
2
Algorithm: roundNo(num) If num is positive then add 0.5. Else subtract 0.5. Type cast the result to int and return.
Example: num = 1.67, (int) num + 0.5 = (int)2.17 = 2. num = -1.67, (int) num – 0.5 = -(int)2.17 = -2. Implementation:
Time complexity: O(1) Space complexity: O(1)
Example: num = 1.67, (int) num + 0.5 = (int)2.17 = 2. num = -1.67, (int) num – 0.5 = -(int)2.17 = -2. Implementation:
Time complexity: O(1) Space complexity: O(1)
keerthana018:
please mark me as brainlist
Similar questions