title: Biggest and smallest of four integers (No arrays, no functions, fewest 'if' statements)
body: <p>You see, I've self-taught myself C++ (not completely, I'm still procrastinating -_-). So, now I started university and they're teaching C and they made us do a program of inputting four integers and we have to tell the largest and smallest out of them. Simple, no?</p>
  
  <p>The thing is, I already have good understanding of functions and arrays. Yes, I CAN program this in arrays, no problem. But since this was the first lab, we haven't 'learned' that yet, so I can't use any of those, it'd be very simple with that.</p>
  
  <p>This is what I wrote there (it feels wrong somehow).</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  int main(void)
  {
      int first, second, third, fourth;
      printf("Enter four integers (separated by space): ");
      scanf("%d %d %d %d", &amp;first, &amp;second, &amp;third, &amp;fourth);
  
      if((first&gt;second) &amp;&amp; (first&gt;third) &amp;&amp; (first&gt;fourth))
          printf("\nFirst number is largest");
      else if((second&gt;first) &amp;&amp; (second&gt;third) &amp;&amp; (second&gt;fourth))
          printf("\nSecond number is largest");
      else if((third&gt;second) &amp;&amp; (third&gt;first) &amp;&amp; (third&gt;fourth))
          printf("\nThird number is largest");
      else if((fourth&gt;second) &amp;&amp; (fourth&gt;third) &amp;&amp; (fourth&gt;first))
          printf("\nFourth number is largest");
  
      if((first&lt;second) &amp;&amp; (first&lt;third) &amp;&amp; (first&lt;fourth))
          printf("\nFirst number is smallest");
      else if((second&lt;first) &amp;&amp; (second&lt;third) &amp;&amp; (second&lt;fourth))
          printf("\nSecond number is smallest");
      else if((third&lt;second) &amp;&amp; (third&lt;first) &amp;&amp; (third&lt;fourth))
          printf("\nThird number is smallest");
      else if((fourth&lt;second) &amp;&amp; (fourth&lt;third) &amp;&amp; (fourth&lt;first))
          printf("\nFourth number is smallest");
  
      printf("\n"); 
      return 0;
  }
  </code></pre>
  
  <p>As you can see, it's too long and boring and complex. But seeing that all we've covered in class for now are <strong>loops</strong> and <strong>decision statements</strong>. Is there a more elegant way of doing this? <strong>One which uses fewer <code>if</code>s</strong>? Not that there is something wrong with this, but it could be better.</p>
  
  <p>P.S. This isn't exactly 'homework' or anything. I made a program, I just wanted to know what I could have done to make it better and to learn better programming practices.</p>