I'm trying to solve a contest problem that was supposed to be simple.
What is the result of the quotient q and remainder r for 2 numbers a and b (-1.000 ≤ a, b < 1.000)?
The input consist of 2 numbers a and b.
Example of 3 different inputs:
7 3
7 -3
-7 3
The output is the quotient q followed by the remainder r of the division of a by b.
Example of output:
2 1
-2 1
-3 2
My code :
#include<stdio.h> int main(){ int a,b; scanf("%d %d",&a,&b); int r = 0; if(a > 0) r = a%b; if(a < 0) r = (a%b + b)%b; printf("%d %d\n",(a-r)/b,r); } My solution is wrong in 10% of the test cases and i don't know what is wrong.