title: Sum of Digits of a Five Digit Number in c?Could you spot the error?
body: <p>BTW I know that's not the most efficient way to do it but if I wanted to do it like I did, what did I do incorrectly? The task was: <em>Given a five digit integer, print the sum of its digits.</em></p>
  <p>Constraint: 10000 &lt;= n &lt;= 99999<br>
  Sample Input: <code>10564</code><br>
  Sample Output: <code>16</code><br></p>
  <p>My code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;math.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main() {
      int n, sum;
      int remainder_array[4] = { n % 1000; n % 100, n % 10, n };
      int digits_array[4];
  
      scanf(&quot;%d&quot;, &amp;n);
      // Complete the code to calculate the sum of the five digits on n.
      if (10000 &lt;= n &amp;&amp; n &lt;= 99999) {
          else if (remainder_array[0] = 0) {
              digits_array[0] = (n - remainder_array[0]) / 1000; 
              n = remainder_array[1];
          } else if (remainder_array[1] != 0) {
              digits_array[1] = (n - remainder_array[1]) / 100;
              n = remainder_array[2];
          } else if (reminder_array[2] != 0) {
              digits_array[2] = (n - remainder_array[2]) / 10;
              n = remainder_array[3];
          } else if (reminder_array[3] != 0) {
              digits_array[3] = n - remainder_array[3];
          } else {
              printf(&quot;%d&quot;, n / 1000);
          }
          sum = digits_array[0] + digits_array[1] + digits_array[2] + digits_array[3];
          printf(&quot;%d&quot;, sum);
      }
      return 0;
  }
  </code></pre>