I have the following code
#include <stdio.h>
int main(void)
{
printf("%d\n", -8%5);
printf("%d\n", 8%-5);
printf("%d\n", -8%-5);
return 0;
}
The output I get is
-3
3
-3
How is it that -8%5 and 8%-5 have different signs, especially when the results of -8/5 and 8/-5 have the same output ?
Also why does -8%-5 give -3 as the output, when -8/-5 gives it's output as 1 ?