title: Function in C to find max element in an array
body: <p>You are participating in a game in which players collect points for various solved puzzles. In the end, the player with the highest score wins. You would like to know how far behind the highest-scoring person everyone else is in order to know whether you still have a chance at winning.</p>
  <p>Please write a C program that uses a function &quot;behind()&quot; (which you also have to write) in order to help with this task. Your program should first read, from the user input, the number of players participating in the game. There are never more than 10 players in the game. Next, your program should read the current scores of each player and store them in an array. Then you should call the function behind(), to which you pass as a first argument, the array holding the player's scores, and as a second argument the number of players in the game. The function behind should replace the scores stored in the array with the number of points by which each individual player is behind the top-scoring player.</p>
  <p>To help you out, the main function of the program has already been written, so your job is simply to write the function behind(), whose protoype is also given to you.</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  void behind(int *, int);
  
  int main(void) {
  int array[10];
  int N, i;
  
  scanf(&quot;%d&quot;, &amp;N);
  for (i=0; i&lt;N; i++) {
      scanf(&quot;%d&quot;, &amp;array[i]);
  }
  behind(array, N);
  for (i=0; i&lt;N; i++) {
      printf(&quot;%d\n&quot;, array[i]);
  }
  
  return 0;
  }
  </code></pre>
  <p>My question is how I write the code to find the max value of the array elements without comparing the last element to something outside the memory block? I have something in mind like:</p>
  <pre><code>if(array[i] &gt; array[i+1]) {
  max = array[i];
  } else {
   max = array[i+1];
  }
  </code></pre>
  <p>but realize it goes outside the bounds of the array once reaching the last element.</p>