The result of division and remainder on negative numbers

I saw a question in the fourth edition of the algorithm before, and now the compiler tries it





The remainder and the dividend have the same sign

14 ÷ -3 = -4 ··· 2

-14 ÷ -3 = 4 ··· -2

-14 ÷ 3 = -4 ··· -2

Regarding the quotient, the quotient of the expression a/b is rounded toward 0, that is, negative numbers are rounded up, and positive numbers are rounded down, similar to the rounding of positive and negative numbers.

If you don't know what rounding is, the simple notation is a number line, which increases from left to right. You rotate the number line 90° counterclockwise, and increase from bottom to top. Is it rounding up and down? Simple memory a lot? For example, 4.3 is rounded down to 4, rounded up to 5, -3.22 rounded down to -4, rounded up to -3, and the number line can be viewed vertically. This is how I remember it.

============================== I am a slow programmer ============= =============

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325947327&siteId=291194637
Recommended