質問

int a = 978;
int b = 24;
int c = a - (a / b) * b;

c seems to be remainder of division of a and b but i don't believe that operator % is doing exactly the same. So what's the trick?

役に立ちましたか?

解決

The % operator does actually do exactly that. Your method is safe as long as b != 0, but the same thing goes when using %.

他のヒント

a - (a/b) * b = a % b

c=a%b calculates the remainder of a when divided by b and is stored in c.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top