Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does 3 modulo 7 = 3?

Tags:

modulo

I was wondering how modulo works. I know how it works when the bigger number comes first, but not the opposite. I know that 7 % 3 = 1 as 3 goes up to 7 2 times and the remaining is 1. However, when it's 3 % 7. I have used the calculator it shows 3. Is this because 7 goes up to 3 zero times and the remaining is 3? Is that how it works?

like image 456
App Avatar asked Oct 20 '25 17:10

App


2 Answers

Your reasoning is correct. Any time the divisor is larger than the dividend, the result of the modulo operation equals the dividend.

like image 63
Justin Niessner Avatar answered Oct 22 '25 12:10

Justin Niessner


7*x + y = 3, x and y are int, and x >= 0,

what y = ?

yes, y = 3.

like image 20
urlreader Avatar answered Oct 22 '25 13:10

urlreader