# TOPIC

why this code is indicating 5% wromg answer?.

#### gnm asked 9 months ago

include

int main () { int e,f,a,b; scanf ("%d%d",&a,&b); if (a<0) { if (b<0) { e=a/b; f=a-be; } else if (b>0) { e=(a/b)-1; f=a-be; } } else { if (b<0||b>0) { e=a/b; f=a-e*b; } } printf ("%d %d\n",e,f); return 0; }

Remember not post solutions. Your post may be reviewed by our moderators.

• #### feodorv replied 9 months ago

You can consider the following inputs:

``````-3 -2
-2 -3``````

You code gives

``````1 -1
0 -2``````

which is incorrect because r should be nonnegative. Also for the input

``-3 3``

``-2 3``

``-1 0``
• #### feodorv replied 9 months ago

You can try another inputs:

``````-4 2
-4 -2``````

``````-2 0
2 0``````

``````-3 2
3 2``````

You have now too complex code. The difficulty arises only when a % b < 0. No need to check all poosible variants of input values.

• #### gnm replied 9 months ago

include

int main () { int e,f,a,b,c; scanf ("%d%d",&a,&b); if (a>=0&&b>0) { e=a/b; f=a -b*e; } else if (a>=0&&b<0) {

``````    e=(a/b);
f=a - (b*e);
}
else if (a<0&&b>0)
{
c=a*(-1);
if (c==b)
{
e=a/b;
f=a-e*b;
}
else
{
e = (a/b)-1;
f= a-b*e;
}

}
else
{
if (a==b)
{
e=(a/b);
f=a-e*b;
}
else
{
e= (a/b)+1;
f= a - b*e;
}
}
printf ("%d %d\n",e,f);
return 0;``````

}

in this code ??? again 5% wrong answer!!!!!!!1