Modular Division

From TRCCompSci - AQA Computer Science
Jump to: navigation, search


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).


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");
    Console.WriteLine("temp is odd");