Then use strings. Floating-point is inherently imprecise due to the limitations of the machine and gains or losses from rounding. It's unreasonable to expect the internal representation of a value to be exactly what the user typed for input, especially given that printf() does its own rounding when converting that value back to a string. In this specific case you can normalize the input and output by forcing a precision to the input:
But that doesn't help if the input changes to use 3 characters past the radix, you'd see the same problem in reverse.
haha.. as if i didn't know, that double is an extension of float. :P
i executed the program with double and in all possible cases. i got same ans but I don't know why it happens.. But, as far as answer's concern, we get the same value printed.
with due respect sir waltP,
I'm not giving any wrong information. I never said that using double will solve the problem. I said that it gives the same value. and as i mentioned before, I don't know why it happens