While running the following lines of code:
int i,a;
for(i=0;i<=4;i++)
{
a=pow(10,i);
printf("%d\t",a);
}
I was surprised to see the output, it comes out to be 1
10
99
1000
9999
instead of 1
10
100
1000
10000
.
What could be the possible reason?
Note
If you think it's a floating point inaccuracy that in the above for loop when i = 2
, the values stored in variable a
is 99
.
But if you write instead
a=pow(10,2);
now the value of a comes out to be 100
. How is that possible?