title: how to multiply 2 large numbers?
body: <p>i created a small console app that multiply 2 long int number.
  i don't know where my problem is. this app work fine until the number of digits is 3.</p>
  
  <p>but if number of digit was bigger than 3 , the app's output is wrong. :(</p>
  
  <p>please show me where my problem is that i solve it.</p>
  
  <p>here is my code:</p>
  
  <pre><code>int digits (int n)
  {
      int counter = 0;
      while (n &gt; 0)
      {
          n/=10;
          counter++;
      }
      return counter;
  }
  
  long longMultiply(long a, long b)
  {
      const int S = 3;
      int w,x,y,z;
      int n = max(digits(a),digits(b));
  
      if(a == 0 || b ==0) {
          return 0;
      } else if (n &lt;= S) {
          return a*b;
      } else {
          int m = (n/2);
  
          //first number
          x = a/(10^m);
          y = a%(10^m);
  
          //second number
          w = b/(10^m);
          z = b%(10^m);
  
          return (longMultiply(x,w)*(10^(2*m)) + (longMultiply(x,z) + longMultiply(w,y)))*(10^m) + longMultiply(y,z) ;
  
      }
  }
  
  int main() {
      //digits(12345);
      cout &lt;&lt; longMultiply(100,100);
      return 0;
  }
  </code></pre>