title: Arrays - Sum Of Two numbers as arrays of digits
body: <p>Take as input N, the size of array. Take N more inputs - digits between 0 and 9 - and store that in an array. Take as input M, the size of second array and take M more input digits and store that in second array. Write a function that returns the sum of the numbers represented by the two arrays. Print the value returned.</p>
  <p>Input:</p>
  <p>4</p>
  <p>1 0 2 9</p>
  <p>5</p>
  <p>3 4 5 6 7</p>
  <p>Output:</p>
  <p>3, 5, 5, 9, 6, END</p>
  <p>Below is the code I have written for it, but it's not giving any result rather it crashes.</p>
  <pre><code>using namespace std;
  int main()
  {
      int tsum,n,m,s,carry=0;
      cin&gt;&gt;n;
      int a[n],sum[]={0};
      for(int i=0; i&lt;n; i++)
      {
          cin&gt;&gt;a[i];
      }
      cin&gt;&gt;m;
      int b[m];
      for(int i=0; i&lt;m; i++)
      {
          cin&gt;&gt;b[i];
      }
      s=max(n,m);
      sum[s] = {0};
      while(n&gt;0 and m&gt;0)
      {
          tsum=a[n]+b[m]+carry;
          sum[s] = tsum%10;
          carry = tsum/10;
          n--;
          m--;
          s--;
      }
      if(n&gt;m)
      {
          while(n&gt;0)
          {
              tsum=a[n]+carry;
              sum[s] = tsum%10;
              carry = tsum/10;
              n--;
              s--;
          }
      }
      if(m&gt;n)
      {
          while(m&gt;0)
          {
              tsum=b[m]+carry;
              sum[s] = tsum%10;
              carry = tsum/10;
              m--;
              s--;
          }
      }
      
  
      for (int i=1; i&lt;s; i++)
      {
          cout&lt;&lt;sum[i]&lt;&lt;&quot;, &quot;;
      }
      cout&lt;&lt;&quot;END&quot;;
      return 0;
  }```
  </code></pre>