The answer for 2 4 0 should be ~4.47, but since you (implicitly) cast that result to int, the value is truncated and 4 remains.
In this particular case, 4 happens to be closer to the real value.
The worrying thing is that you are using integers to store the results of calculations that result in real numbers.