Difference between revisions of "Modular Division"
(Created page with "=Explanation= In C# the modular division character is % In C# the standard division character is / Modular division will return the remainder only from the division. For exa...") |
(No difference)
|
Latest revision as of 12:33, 6 February 2024
Explanation
In C# the modular division character is %
In C# the standard division character is /
Modular division will return the remainder only from the division. For example modular division of 10 by 3 would be 3 (it divides 3 times) with a remainder of 1 (the bit left over).
Example
You can use modular division to tell if a number is odd or even:
int temp = 9;
if(temp % 2 == 0)
{
Console.WriteLine("temp is even");
}
else
{
Console.WriteLine("temp is odd");
}