C# C# Basics (Retired) Perfect Integers and Doubles

shobanaannadurai
shobanaannadurai
4,200 Points

Please fill in the correct answer in each blank provided below.

int a=3; int b=2; double c=3.5; double y=a/b*c;

Ans i have given y=0.4286.

But its wrong can anyone help me on this.

as (3/2) * (3.5) // 3/2 = 1 two int 1 * 3.5 = 3.5

1 Answer

Hakim Rachidi
Hakim Rachidi
32,051 Points

You first have to divide 3 by 2 (both int so you truncate the result) which is 1 (without truncation 1.5). Finally multiply 1 (int) by 3.5 (double) which results in a double: 3.5;

y = 3.5;