top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to find if two numbers are with different sign?

+3 votes
295 views

Given two numbers say int32, please help to write a function that returns true if the signs of given integers are different, otherwise false.

posted Nov 29, 2013 by Sanketi Garg

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Check this, logic is simple if highest bit xor is 1 then different sign else same sign

bool different_sign (int a, int b)
{
    return ((a ^ b) < 0);
}
answer Nov 29, 2013 by Salil Agrawal
Similar Questions
+4 votes

Two numbers a and b are said to be co-prime if gcd(a,b) is 1.

Now my question is about the algorithm to find out if given two numbers are co-prime.

+7 votes

You have a 2D matrix. Only two ZEROs in matrix.
Find the path from 1st zero to 2nd zero with least sum.

1       6       8       9       0       3

4       9       -5      5       11      13

8       9       44      23      15      -20

7       9       7       -13     14      11      

0       16      23      31      16      7

67      5       4       23      21      19

Answer

1       6       8       9       0  ----> 3
                                         |
4       9       -5      5       11      13
                                         |
8       9       44      23      15      -20
                                         |
7 <---- 9 <---- 7 <--- -13 <--- 14 <---  11     
|
0       16      23      31      16        7

67      5       4       23      21       19
...