此文章來自奇摩知識+如有不便請留言告知



標題:

C++: (-17)%5 and 17%(-5)

發問:

我呢排學緊C++ 我知道cout <<17%5會出2 點解(-17)%5出-2 點解17%(-5)出2 詳細解一下,THX!!!

最佳解答:

The C++ standard requires that (a/b)*b + a%b == a, we can rearrange this to a%b == a-(a/b)*b. And that explains everything.5.6/4 [...] if the quotient a/b is representable in the type of the result, (a/b)*b + a%b is equal to a.

其他解答:6CC7293C79127CE5
arrow
arrow
    文章標籤
    我知道 文章 奇摩 C++
    全站熱搜

    hsf272g 發表在 痞客邦 留言(0) 人氣()