Skip to main content

This works for positive or negative numbers.:

q = x/y+((x%y!=0)?!((x>0)^(y>0)):0);

q = x / y + ((x % y != 0) ? !((x > 0) ^ (y > 0)) : 0); 

If there is a remainder, checks to see if xx and yy are of the same sign and adds 11 accordingly.

This works for positive or negative numbers.

q = x/y+((x%y!=0)?!((x>0)^(y>0)):0);

If there is a remainder, checks to see if x and y are of the same sign and adds 1 accordingly.

This works for positive or negative numbers:

q = x / y + ((x % y != 0) ? !((x > 0) ^ (y > 0)) : 0); 

If there is a remainder, checks to see if x and y are of the same sign and adds 1 accordingly.

Source Link

This works for positive or negative numbers.

q = x/y+((x%y!=0)?!((x>0)^(y>0)):0);

If there is a remainder, checks to see if x and y are of the same sign and adds 1 accordingly.