|
C Programming Reference >> C Programming Reference Question Bank >> 28/05/07 - 680 Views - Ratings : Question - Guess the output of the following code?
int main ()
{
printf ( "%lf", (0.99 - 0.9 -0.09);
return 0;
}
Answer -
-2.7755575615628914E-17 Explanation - Above result can vary from computer to computer, compiler to compiler but it is never 0. Why? Even though normal arithemetic easily concludes the answer to be zero, but why computer arithemetic doesnot. The reason can be easily justified, see closely the answer has magnitude E-17 thats a very very tiny number approximately zero but not exactly zero. The explanation for this anomaly is computer uses a finite number of bits to store a number no matter how precise it is. Not all real numbers can be stored in bits form exactly and when attempted results in approxiamtion which effect the final output. So the answer is that such a result is produce because of bit-level approximation done by computer. Reader Comments -
|
||