What values integer gets? When i wrote this code the output was 0 and not 0.333333
int a=18;
Int b=6;
int c=b/a;
Console.WriteLine(c);
thank you (:
What values integer gets? When i wrote this code the output was 0 and not 0.333333
int a=18;
Int b=6;
int c=b/a;
Console.WriteLine(c);
thank you (:
The answer is in your question, integer can only hold integer value (...,-2,-1,0,1,2,...) so 6/18 would be 0. You could expect otherwise if 2 of these conditions are met:
1.c (the variable result is assigned) can hold floating type (float, double, decimal)
To describe (2) a bit more:
if either of a or b is of floating point type, you implicitly casting the result to a floating point value.
double a = 6;
int b = 18;
double c =a / b;
or you explicitly say that the int values (at leat one of them) should be considered as floating point:
int a = 6;
int b= 18;
double c = (double)a/(double)b;
double c = (double) a/b;
All you need to know about types
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/types