title: Multiplication of large numbers represented as arrays?
body: <p>The numbers are stored in the arrays with their digits in reverse order. Here is a functions that should multiply two numbers, <code>lhs</code> and <code>rhs</code>, and store the product in <code>result</code>:</p>
  
  <pre><code>public static void MultiplyDigitArrays(int[] lhs, int[] rhs, int[] result)
  {        
       int length1 = Math.Max(lhs.Length, rhs.Length);
       for (int i = 0; i &lt; length1; i++)
       {
          int[] PartialProduct = new int[result.Length];
  
          int length2 = Math.Min(lhs.Length, rhs.Length);
          for (int j = 0; j &lt; length2; j++)
          {
              int multiplicand = (lhs.Length &lt; rhs.Length) ? rhs[i] : lhs[i];
              int multiplier = (lhs.Length &lt; rhs.Length) ? lhs[j] : rhs[j];
  
              int product = PartialProduct[i + j] + multiplicand * multiplier;
  
              PartialProduct[i + j] = product % 10;
              int carry = product / 10;
  
              PartialProduct[i + j + 1] = PartialProduct[i + j + 1] + carry;
          }
          SumDigitArrays(PartialProduct, result, result);
      }
  }
  </code></pre>
  
  <p>However, if I multiply:</p>
  
  <pre><code>static void Main(string[] args)
  {
      int[] n1 = { 1, 1 };
      int[] n2 = { 1, 1 };
      int[] result = new int[Math.Max(n1.Length, n2.Length) * 2 + 1];
  
      MultiplyDigitArrays(n1, n2, result);
  
      PrintArray(result);
  
      Console.WriteLine();
  }
  </code></pre>
  
  <p>the result is:</p>
  
  <pre><code>00132
  </code></pre>
  
  <p>instead of the expected:</p>
  
  <pre><code>00121
  </code></pre>
  
  <h3>What am I doing wrong?</h3>
  
  <hr>
  
  <p>For the MCVE:</p>
  
  <pre><code>public static void PrintArray(int[] Array)
  {
      int length = Array.Length;
      for (int i = length - 1; i &gt;= 0; i--)
      {
          Console.Write(Array[i]);
  
      }
  }
  
  public static void SumDigitArrays(int[] a, int[] b, int[] result)
  {
      int length = Math.Max(a.Length, b.Length);
      for (int i = 0; i &lt; length; i++)
      {
          int lhs = (i &lt; a.Length) ? a[i] : 0;
          int rhs = (i &lt; b.Length) ? b[i] : 0;
  
          int sum = result[i] + lhs + rhs;
          result[i] = sum % 10;
  
          int carry = sum / 10; 
  
          if (i + 1 &lt; result.Length)
          {
              result[i + 1] = result[i + 1] + carry;
          }
      }
  }
  </code></pre>