why is this happening?
including all necessary header files ,math.h and stdio.h ,
int main()
{
int I=2;
int y=pow(10,I);
printf("%d",y);
return 0;
}
this program prints 99.
can u help;
thank u.
![]() |
why is this happening?
including all necessary header files ,math.h and stdio.h ,
int main()
{
int I=2;
int y=pow(10,I);
printf("%d",y);
return 0;
}
this program prints 99.
can u help;
thank u.
a text book example of 'loss of precision due to conversion from floating type to integer type'
pow( x, y) returns a double. When you try to put that inside an int, you experience a roundoff error.
pow is defined as:
double pow(double x, double y);
so the two integers you supply, 10 and I, are cast into doubles, the function is evaluated and a double is returned. When that double is then cast into an int so that it can be stored in y some precision is lost due to the way that floating point numbers are represented.
hope this helps.
I don't know what the problem is because my compiler isn't showing any problem and printing 100 as the answerQuote:
Originally Posted by muziti
May be your math.h has been tampered
If you get any more such problems, try loading turbo c again and then use it
All times are GMT -7. The time now is 05:31 AM. |