0

Modulo with negative numbers

Can someone explain why these 2 lines in code give different results https://code.sololearn.com/ctGo1AQLJ1Vr/?ref=app

19th Oct 2021, 3:43 AM
Tim
Tim - avatar
1 Réponse
+ 1
6%-4 = 2 because 6/-4 = -1 + R/-4 R = 6 - (-1*-4) = 6 - (+4) = 2 -6%4 = -2 because -6/4 = -1 + R/4 R = -6 - (-1*4) = -6 - (-4) = -2
20th Aug 2022, 3:24 AM
Brian
Brian - avatar