title: how to check for the 1st element and last element in array c++
body: <p>Compute the smoothed array by doing this: Each value <code>smooth[N]</code> is
  the average of three values: <code>signal[N-1]</code>, <code>signal[N]</code>, and <code>signal[N+1]</code>. </p>
  
  <p>For the first element of
  smooth, average the first two elements of signal. For the last element of smooth, average the
  last two elements of signal.</p>
  
  <p>How do I check for the 1st element and last element? Is using a <code>for</code>-loop wrong? Here is what my function looks like. </p>
  
  <pre><code>void smoothArray(const int sig[], int result[], int len)
  {
  
      for (int i = 0; i &lt; len; i++)
      {
  
          result[i] = (sig[i - 1] + sig[i] + sig[i + 1]) / 3;
      }
      return;
  }
  </code></pre>