+ 1
Does anyone know why this code always returns 0 ?
This is a simple linear function https://code.sololearn.com/cfukJ8ine050/?ref=app
3 Respostas
+ 3
(1/2)*x
=0*x
=0
When both operands of the division are integers, the result is an integer division which produces the quotient.
Adding the decimal point makes it a floating point literal:
(1.0/2.0)*x
or
x/2.0
+ 3
add a type cast to this line like this:
double y=((double)1/2)*x;
+ 1
Thank you . Solved