/ Published in: Java
-13%2 = -1 so this might cause problem in your program sometime. So always write your code in such a way that it never cause any problem in sleep also.. :) Use anyone of the following code snippet.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
int mod(int x, int m) { return (x%m + m)%m; } int mod(int x, int m) { int r = x%m; return r<0 ? r+m : r; }