How does the modulus operator work on negative numbers? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

How does the modulus operator work on negative numbers?

10th Jun 2020, 5:11 PM
M Tamim
M Tamim - avatar
3 Answers
+ 6
Seb TheS 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 Thanks, guys. It really helps. Abhay Bro, not everything can be found on solo experiments, right? I figured out how floor division works on negative numbers but I couldn't figure out how % works. So I chose to ask.
11th Jun 2020, 6:22 AM
M Tamim
M Tamim - avatar
+ 2
When b is negative: a % b = c Then: b < c <= 0 c = a - n*b (n can be any whole number)
10th Jun 2020, 7:06 PM
Seb TheS
Seb TheS - avatar
- 1
M Tamim find ur ans by Tryiny it on code playground
10th Jun 2020, 5:16 PM
Abhay
Abhay - avatar