I am struck with some floating-point precision. Please help me to get through this.
main()
{
int fact,i=5,div=8;
float dec=0.427,temp,sum=0;
while(i)
{
temp=dec*10; printf("%f\t",temp);
fact=(int)temp;
sum=sum+(fact/(float)div); printf("%f\n",sum);
dec=temp-fact;
div=div*8;
i--;
}
printf("\n The Decimal part= %f",sum);
getch();
}
Output
4.270000 0.500000
2.700000 0.531250
6.999998 0.542969
9.999981 0.545166
9.999809 0.545441
The Decimal part= 0.545441
Thanks in advance :)