A modulo operation a%b returns the remainder for a/b but for negative numbers it does not do so.
#include <stdio.h>
int main(void) {
  int n=-4;
  printf("%d\n",n%3);
  return 0;
}
It should return 2  as 3*(-2)=-6 is just smaller than -4 and a multiple of 3 but the output is -1. 
Why is it treating (-a) mod b same as -(a mod b)
 
     
    