X is a int in this problem y is the float what are the value

X is a int in this problem y is the float what are the values
Y=20/3*4;

Y=25*2/(3/2);

Y=25*2/3;

X=25*2/3;
X is a int in this problem y is the float what are the values
Y=20/3*4;

Y=25*2/(3/2);

Y=25*2/3;

X=25*2/3;
Y=20/3*4;

Y=25*2/(3/2);

Y=25*2/3;

X=25*2/3;

Solution

Here the result won\'t depend on the type of X and Y, because whenever the mathematical expression execute it will type cast the result according to the value (int, float etc) and lastly the result will be assigned to X or Y.

Take the first expression i.e Y = 20/3*4;

here first division will be done, so 20/3 = 6.666... but here 20 and 3 both are int type so the compiler will convert the subresult as 6. now the second operator come into the picture and multiplication will happen so, 6*4= 24 is the answer for the first statement. suppose if you write 20.0/3*4 then it will give floating result because one of the value from 20 and 3 is float value so it will convert the result in float. And this floating result again multiply with integer will give float result. If you make Y float it means that the result which is already calculated is assigned to a float variable. If the result is 24 it will treat as 24.00.

Now, in the second expression the concept is same. So, the calculation is like first brackets will be executed so,3/2 = 1 because both are integer only so the result is also integer. now 25*2/1 will execute like 25*2= 50 and 50/1 = 50. so the answer of second expression is 50.

Third expression i.e 25*2/3 will excute like 25*2 = 50 and 50/3 = 16 because both are integer. so the answer is 16.

Now, last expression is also same as previous one and the result is also same. i.e 16

X is a int in this problem y is the float what are the values Y=20/3*4; Y=25*2/(3/2); Y=25*2/3; X=25*2/3; X is a int in this problem y is the float what are the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site