title: Can anyone explain this algorithm for calculating large factorials?
body: <p>i came across the following program for calculating large factorials(numbers as big as 100).. can anyone explain me the basic idea used in this algorithm??
  I need to know just the mathematics implemented in calculating the factorial.</p>
  
  <pre><code>#include &lt;cmath&gt;
  #include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  
  using namespace std;
  
  int main()
  {
  
        unsigned int d;
  
        unsigned char *a;
  
        unsigned int j, n, q, z, t;
  
        int i,arr[101],f;
  
        double p;
  
  
      cin&gt;&gt;n;
      p = 0.0;
      for(j = 2; j &lt;= n; j++)
          p += log10(j);
      d = (int)p + 1;
      a = new unsigned char[d];
      for (i = 1; i &lt; d; i++)
          a[i] = 0; //initialize
      a[0] = 1;
      p = 0.0;
      for (j = 2; j &lt;= n; j++)
      {
          q = 0;
          p += log10(j);
          z = (int)p + 1;
          for (i = 0; i &lt;= z/*NUMDIGITS*/; i++)
          {
              t = (a[i] * j) + q;
              q = (t / 10);
              a[i] = (char)(t % 10);
          }
  
      }
      for( i = d -1; i &gt;= 0; i--)
          cout &lt;&lt; (int)a[i];
      cout&lt;&lt;"\n";
      delete []a;
  
  return 0;
  }
  </code></pre>