Modular Division

From TRCCompSci - AQA Computer Science
Revision as of 12:33, 6 February 2024 by Admin (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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");
}