title: How to get the largest and smallest of 3 values with fewest comparisons?
body: <p>This is a simple introduction course question. I have to write a program that asks the user to input 3 numbers, and determines the largest and smallest number.</p>
  <p>I need to only use <code>if</code> statements.</p>
  <p>This is what I tried so far: which required 4 comparisons.</p>
  <pre><code>int x, y, z;
  int smallest, largest; 
  cout &lt;&lt; &quot;Please enter 3 numbers to compare: &quot; ;
  cin &gt;&gt; x &gt;&gt; y &gt;&gt; z;
  
  smallest = x;
  largest = x;
  
  if (y &gt; largest) 
          largest = y;
  if (z &gt; largest)
          largest = z;
  if (y &lt; smallest)
          smallest = y;
  if (z &lt; smallest)
          smallest = z;
  
  cout &lt;&lt; &quot;largest: &quot; &lt;&lt; largest &lt;&lt; &quot;, and smallest: &quot; &lt;&lt; smallest &lt;&lt; endl;   
  </code></pre>
  <p>My question is: Is it possible to only use 3 comparisons, or less? I think when <code>y &gt; largest</code>, it also tells us something else as well?</p>