C# C# Basics (Retired) Perform Order of Operations

I don't understand the modulus operator. how do you perform this on a calculator? how are you getting the answers?

I don't understand the modulus operator. how do you perform this on a calculator? how are you getting the answers?

2 Answers

joelearner
joelearner
36,552 Points

Hi Joe,

The modulus is the remainder from a division operation. So if you have 15/5, you will get 3 and no remainder. The modulus is 0 here. Or if you have 18/4, you will get 4 and a remainder of 2. The modulus here is 2.

For example, if you had this: 5 * 2 + 9 % 4 + 8 / 4 Then you have 5 * 2 = 10, 9 % 4 = 1, 8 / 4 = 2 or 10 + 1 + 2 and your answer will be 13.

Cheers!

thank you! I also discovered that if you're doing this on a calculator it will give you a decimal. to convert to the remainder, your multiply the decimal to the divisor. Thanks!

Allan Clark
Allan Clark
Treehouse Moderator 10,798 Points

If joelearner provided helpful information and answered your question please take the time to upvote his answer and select as 'Best Answer', it will mark this question as closed and give him some swag points for his time :)

Happy Coding!