0
#include<stdio.h>

int main(void)
{
    float val = (4 / 14) ;
    printf("%f\n",val);
}

I don't know what the problem is but it returns 0.00000 instead of 0.285714...

  • 2
    Since both `4` and `14` are *integers*, then `4 / 14` is an integer division with an integer result. – Some programmer dude Feb 05 '21 at 11:46
  • 2
    Because you're dividing two integers, which produces an integer (0), which you only then convert to a float. – user4815162342 Feb 05 '21 at 11:46
  • 2
    Does this answer your question? [What is the behavior of integer division?](https://stackoverflow.com/questions/3602827/what-is-the-behavior-of-integer-division) – Mansoor Feb 05 '21 at 11:46
  • 1
    And to rectify it, you can write `float val = (float)4 / 14;` or `float value = 4.0 / 14;` – lurker Feb 05 '21 at 11:55

0 Answers0