I have a dump question! Why 3/2=1 though z is float not integer?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I have a dump question! Why 3/2=1 though z is float not integer??

https://code.sololearn.com/c01jmqx6IkQQ/?ref=app

27th Jun 2017, 8:31 AM
Abdul Aziz Al-Ayoubi
Abdul Aziz Al-Ayoubi - avatar
2 Answers
+ 3
x and y also need to be floats because if you divide an int by an int the answer will be an int
27th Jun 2017, 8:42 AM
johan beimers
johan beimers - avatar
+ 3
write like below. int x = 3; int y = 2; float z = (float)x / y; Console.WriteLine(
quot;z = {z}\nx / y = {(float)x/y}");
27th Jun 2017, 9:23 AM
Atiye Khajepour
Atiye Khajepour - avatar