What is a practical application for modulus? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is a practical application for modulus?

11th Jul 2016, 6:05 PM
Connar
Connar - avatar
6 Answers
+ 2
I've used this in the past to detect even vs odd numbers by doing number % 2 if the result is 0 even, otherwise odd
13th Jul 2016, 6:10 AM
Ian Jones
Ian Jones - avatar
+ 1
In one of my MVC Web applications I use it to determine creation of a new row/column sequence. In this scenario you can say if the number of columns x is evenly divisible by max columns in a row y then create new row. In the example given in the solo learn c# tutorial it is effectively being used to determine a boolean value and return a result if true else return a different value.
30th Jul 2016, 3:28 PM
Mike
Mike - avatar
0
it can for instance be used to bound a value instead of using if statements.
12th Jul 2016, 11:44 AM
Bernhard Eriksson
Bernhard Eriksson - avatar
0
@Bernhard Eriksson sorry I'm new to this and have no idea what that means haha
12th Jul 2016, 6:16 PM
Connar
Connar - avatar
0
@Ian Jones brilliant, thank you
13th Jul 2016, 10:15 PM
Connar
Connar - avatar
0
@Connar instead of using if statements to set a max value you can use modulus which is faster than doing if.
11th Dec 2016, 3:05 PM
Bernhard Eriksson
Bernhard Eriksson - avatar