0

I'm trying to use a for-loop to print out numbers with a step of 0.1 and my output is coming out weird.

My code:

    int main()
{
    float i;
    for(i=1.0;(int) i<=9;i=i+0.1)
    {
        printf("%f ",i);
    }
    return 0;
}

It outputs everything just fine up until 2.700000 and then goes 2.799999,2.899999,2.999999 etc. What's going on?

Alex Matt
  • 209
  • 1
  • 4

0 Answers0