Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We're not going to do your homework, but let me add some hints on how to proceed. We assume that we're going to compare <em>a</em> and <em>b</em>.</p> <ol> <li>As <a href="https://stackoverflow.com/questions/1741010/c-program-to-compare-integers-without-using-logical-operators/1741031#1741031">Carl states</a>, you may want to look at the difference <em>d = a - b</em>. <ul> <li>Observation: <em>d</em> can be negative, zero or positive.</li> <li>Question: which value of <em>d</em> corresponds to which (in)equality of <em>a</em> and <em>b</em>?</li> </ul></li> <li>Once you have calculated <em>d</em> and know how to interpret it, you have to find ways to inspect it without using logical operators. <ul> <li>Observation: obvious candidates are the <a href="http://www.cprogramming.com/tutorial/bitwise_operators.html" rel="nofollow noreferrer">bitwise operators</a>.</li> <li>Question: but how do computers (usually) store integers?</li> <li>Hint: have a look at <a href="http://en.wikipedia.org/wiki/Two%27s_complement" rel="nofollow noreferrer">two's complement</a>.</li> <li>Question: how can you tell the difference between a negative and a non-negative number?</li> </ul></li> <li>Now you have all information needed to answer the question. <ul> <li>Hint: you <em>are</em>, of course, allowed to use <code>if</code> and <code>else</code> statements.</li> <li>Bonus hint: you may want to use <code>INT_MIN</code> from <code>limits.h</code>.</li> </ul></li> </ol> <p><strong>Edit:</strong> this answer, and most other answers here assume that the OP is not allowed to use <a href="http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Logical_operators" rel="nofollow noreferrer"><em>logical</em></a> and <a href="http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Comparison_operators.2FRelational_operators" rel="nofollow noreferrer"><em>relational</em></a> (<em>comparison</em>) operators. However, the OP only explicitly mentions that logical operators are disallowed. I think the main reason for this misunderstanding is the fact that the problem is trivial to solve using comparison operators.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload