title: Can add very large numbers but not small numbers in C
body: <p>I have a C program that can add large numbers and it works fine but I also need to do add smaller numbers but I get a odd output and am not sure where the error is coming from.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  
  int main() {
  int num1[255], num2[255], sum[255], m = 0, z, x = 0;
  char s1[255], s2[255], in[255];
  int l1, l2;
  
  printf("enter the input as a+b=\n");
  scanf("%s", in);
  for (z = 0; in[z] != '+'; z++) {
      s1[z] = in[z];
      m++;
  }
  
  for (z = m + 1; z &lt; strlen(in) - 1; z++) {
      s2[x] = in[z];
      x++;
  }
  
  for (l1 = 0; s1[l1] != '\0'; l1++)
      num1[l1] = s1[l1] - '0';
  for (l2 = 0; s2[l2] != '\0'; l2++)
      num2[l2] = s2[l2] - '0';
  
  int carry = 0;
  int k = 0;
  int i = l1 - 1;
  int j = l2 - 1;
  
  for (; i &gt;= 0 &amp;&amp; j &gt;= 0; i--, j--, k++) {
      sum[k] = (num1[i] + num2[j] + carry) % 10;
      carry = (num1[i] + num2[j] + carry) / 10;
  }
  
  if (l1 &gt; l2) {
      while (i &gt;= 0) {
          sum[k++] = (num1[i] + carry) % 10;
          carry = (num1[i--] + carry) / 10;
      }
  
      if (carry != 0) {
          sum[k] = carry;
          k = k + 1;
      }
  } else if (l1 &lt; l2) {
      while (j &gt;= 0) {
          sum[k++] = (num2[j] + carry) % 10;
          carry = (num2[j--] + carry) / 10;
      }
  
      if (carry != 0) {
          sum[k] = carry;
          k = k + 1;
      }
  } else {
  
      if (carry &gt; 0)
          sum[k++] = carry;
  }
  
  printf("%s+%s=\n", s1, s2);
  
  for (k--; k &gt;= 0; k--)
      printf("%d", sum[k]);
  return 0;
  }
  </code></pre>
  
  <p>If I enter a values such as: </p>
  
  <p>enter the input as a+b=</p>
  
  <p>9999999999999999999999999999+1=</p>
  
  <p>I get this output which is what I wanted it to be</p>
  
  <p>9999999999999999999999999999+1=</p>
  
  <p>10000000000000000000000000000</p>
  
  <p>When I try something smaller like:</p>
  
  <p>123+456=</p>
  
  <p>The output is different </p>
  
  <p>123ó+456=</p>
  
  <p>16-5-6</p>
  
  <p>I don't know where these numbers are coming from and this keeps occurring with any number less than 9999999999999999999999999999+1= It should work for any number not just a single set.</p>