I am trying to learn c programming and I came across this problem which I dont seem to understand. Here is the syntax double x;
int flag = 0;
for(x = 0; x <= 2.0; x+=0.1) {
printf("%f\n",x);
printf("%d\n", x==0.300000);
if(x==0.3) {
printf("yes\n");
flag = 1;
}
}
if(flag == 0) {
printf("no\n");
}
how come the output is no. I though when the loop reaches 0.3, the flag would be set to one and yes would be printed. How come that is not the case?