Basic Concepts Arithmetic Operators C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Basic Concepts Arithmetic Operators C#

What is the output of this code? int x = 16; int y = 5; Console.WriteLine(x/y); is 3.2 but if you have int z=x/y Console.WriteLine(z); then is 3

18th Oct 2016, 2:19 PM
sagabundo
sagabundo - avatar
2 Answers
+ 1
this is because the "/ "can not give us the answer in decimals. for the remainder you will have to use "%" seperately Console.WriteLine(x%y);
22nd Oct 2016, 9:38 AM
Uzair Ahmed
Uzair Ahmed - avatar
0
use variable float for this, after value put 'f' example: 3.2f
20th Oct 2016, 3:06 PM
Gustavo Ribeiro