#include <iostream.h>
#include <math.h>
int main()
{
int j=2;
int output;
output=pow(10,j);
cout<<output;
return 0;
}
I wrote above code to gcc 12 compiler and got the output 99 instead 100. I don't get the valid reason while searching on various sites. Is there any compiler problem?
Because of integer truncation. pow()
returns a floating point value, and due to floating point arithmetic, it is probably ~ 99.999...
; however, due to integer truncation, even 99.999...
gets truncated down to 99.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With