title: Division of very big numbers using arrays in C
body: <p>I'm trying to make a calculator for very big numbers (even bigger than long long) and I'm using arrays to make it work. </p>
  
  <p>So far I have done addition, subtraction and multiplication. But I'm really stuck in division part.</p>
  
  <p><strong>EDIT:
  new progress. as a friend mentioned i need to compare result array with divisor each time so i can stop the progress any time divisor is larger than dividend. I managed to make a nice function to compare it every time. this function is tested separately and it's working fine. OK. now i'm starting to make REAL progress. i got the quotient. now i will try to put quotient in array so that we can work with LARGER numbers!</strong></p>
  
  <pre><code>    #define MAX_SIZE 50
      #define SIZE_USE (MAX_SIZE-1)
  
      int div(int inum_first[], int inum_second[], int div_result[], int firstlen, int secondlen)
  {
      int i;
      int check1 = 0, check2 = 0;
  
      int zeroC = 0;
  
      int tmp[MAX_SIZE];
  
      for (i = 0; i &lt;= SIZE_USE; i++)
      {
          tmp[i] = 0;
      }
  
      int inum_firstCP[MAX_SIZE] = { 0 };
  
      for (i = 0; i &lt;= 1; i++)
      {
          inum_firstCP[i] = inum_first[i]; // create a copy of inum_first
      }
  
      for (i = 0; i &lt;= SIZE_USE; i++)
      {
          if (inum_first[i] != 0)
              check1++;
  
          if (inum_second[i] != 0)
              check2++;
      }
  
      if (secondlen &gt; firstlen)
      {
          zeroC++;
          goto EOI;
      }
  
      if (check2 == 0)
      {
          puts("\nExpected error\n");
          return -1;
      }
  
      int j = 0, p = 0;
  
      int s = 0;
      int o = 1; // o is Quotient!
  
      do
      {
          for (i = SIZE_USE; i &gt;= 0; i--)
          {
              if (tmp[i] = inum_firstCP[i] - inum_second[i] &gt;= 0)
              {
                  tmp[i] = inum_firstCP[i] - inum_second[i];
              }
              else
              {
                  inum_firstCP[i - 1] = inum_firstCP[i - 1] - 1;
                  tmp[i] = (inum_firstCP[i] + 10) - inum_second[i];
              }
  
              inum_firstCP[i] = tmp[i];
  
          }
      if (compare(inum_firstCP, inum_second, firstlen, secondlen) &lt; 0) break;
      j++;
      o++;
      } while (j&lt;MAX_SIZE); // anything else will also work
  
  EOI:
  
      return 0;
  }
  
  int compare(int inum_firstCP[], int inum_second[], int firstlen, int secondlen)
  {
      int c = 0, d = 0;
      int i;
  
      firstlen = MAX_SIZE, secondlen = MAX_SIZE; // temporary. will provide a better solution ASAP
      if (firstlen &gt; secondlen)
      {
          return 1;
      }
      else if (secondlen &gt; firstlen)
      {
          return -1;
      }
      else
      {
          for (i = 0; i &lt; firstlen; i++)
          {
              if (inum_firstCP[i] &gt; inum_second[i]) c++;
              else if (inum_second[i] &gt; inum_firstCP[i]) d++;
          }
          if (c&gt;d) return 1;
          else if (d&gt;c) return -1;
      }
  
      return 0; // else
  }
  </code></pre>