C
C#2mo ago
Robi_imadot

understanding %

No description
36 Replies
Robi_imadot
Robi_imadot2mo ago
I don't understand why this is 1 as output
Robi_imadot
Robi_imadot2mo ago
No description
Robi_imadot
Robi_imadot2mo ago
No description
Robi_imadot
Robi_imadot2mo ago
Its int so it should be a 179 or a 134 not a 23.1 or a 13.4
Robi_imadot
Robi_imadot2mo ago
No description
Robi_imadot
Robi_imadot2mo ago
I remade it with double but still 1
Angius
Angius2mo ago
It's the remainder
SparkyCracked
SparkyCracked2mo ago
I respect the coding on mobile situation. Holy
Robi_imadot
Robi_imadot2mo ago
I divide 100 by 3 and the opposite of the anwser, right?
Angius
Angius2mo ago
13 % 5 = 3 Because 5 fits entirely inside of 13 twice 2 x 5 is 10 13 - 10 is 3
SparkyCracked
SparkyCracked2mo ago
The coding term for '%' is Modulo
Robi_imadot
Robi_imadot2mo ago
So i search for the closest multiplication and add numbers to it until its 100?
SparkyCracked
SparkyCracked2mo ago
If you search up this definition it returns the following:
Modulo is a mathematical operation that returns the remainder of a division of two arguments. It is available in every programming language.
Modulo is a mathematical operation that returns the remainder of a division of two arguments. It is available in every programming language.
Robi_imadot
Robi_imadot2mo ago
So like this?
No description
Robi_imadot
Robi_imadot2mo ago
So the modulo is 1 Alias %
SparkyCracked
SparkyCracked2mo ago
Modulo is the remainder When dividing
Angius
Angius2mo ago
No description
Angius
Angius2mo ago
Green is 13 Red and blue are both 5 The empty space, where another 5 cannot fit, is the remainder
SparkyCracked
SparkyCracked2mo ago
so 100/33 = 3 if you take whats left: 100 - (33*3) = modulo In this case 1
Robi_imadot
Robi_imadot2mo ago
So if i get this again i can just 100/3=33.3333 100/33=3 100 - (33*3)
SparkyCracked
SparkyCracked2mo ago
Note we deal with whole numbers here
Robi_imadot
Robi_imadot2mo ago
Yes, not doubles
SparkyCracked
SparkyCracked2mo ago
Yeah
Robi_imadot
Robi_imadot2mo ago
I think i understand it now, thank you everyone
SparkyCracked
SparkyCracked2mo ago
100/3 = 33 100 - (333) = modulo of 100/3 1 100/33 = 3 100 - (333) = modulo of 100/33 1 I'll send the sudo code now:
c#
num1/intDevider = ans // whole number
num1 - (intDevider*ans) = modulo // your remainder as a whole number
c#
num1/intDevider = ans // whole number
num1 - (intDevider*ans) = modulo // your remainder as a whole number
Hope it makes sense @Ultra Giga Beginner You don't need to / twice ^^
Robi_imadot
Robi_imadot2mo ago
It makes, but i don't know what a sudo code is yet
SparkyCracked
SparkyCracked2mo ago
It's spelt 'pseudocode' but I get lazy lol. I describe it as english code...it doesn't run anywhere, but has some syntax so you can put it in code later. Used for discussing logic. Maybe @ZZZZZZZZZZZZZZZZZZZZZZZZZ has a better way to describe it
Angius
Angius2mo ago
Well, if you wanted to write your own modulo method...
public static int Mod(int num, int divisor)
{
var result = num / divisor;
return num - divisor * result;
}
public static int Mod(int num, int divisor)
{
var result = num / divisor;
return num - divisor * result;
}
MODiX
MODiX2mo ago
Angius
REPL Result: Success
int Mod(int num, int divisor)
{
var result = num / divisor;
return num - divisor * result;
}

var myMod = Mod(14, 8);
var mod = 14 % 8;

new {
MyMod = myMod,
Mod = mod,
Equal = myMod == mod
}
int Mod(int num, int divisor)
{
var result = num / divisor;
return num - divisor * result;
}

var myMod = Mod(14, 8);
var mod = 14 % 8;

new {
MyMod = myMod,
Mod = mod,
Equal = myMod == mod
}
Result: <>f__AnonymousType0#1<int, int, bool>
{
"myMod": 6,
"mod": 6,
"equal": true
}
{
"myMod": 6,
"mod": 6,
"equal": true
}
Compile: 330.227ms | Execution: 65.915ms | React with ❌ to remove this embed.
Angius
Angius2mo ago
Man, I'm glad we learned division with remainder in primary school, before we even learned proper division lol It seems to stump so many people
SparkyCracked
SparkyCracked2mo ago
Yep
Robi_imadot
Robi_imadot2mo ago
Okay, i can't comprehend this yet, but later i hope I'll. I kind of understand it but if i would need to write this out from head with logic i would not be able to
Angius
Angius2mo ago
Exercise
SparkyCracked
SparkyCracked2mo ago
Normally the case when learning new things in code It's normal don't stress. Just keep practicing
Angius
Angius2mo ago
Try calculating some modulos, then check with C# if you got the answer right
Tvde1
Tvde12mo ago
÷ and % are not the same unfortunately