Ad
Code
Diff
  • inline int multiply(int x, int y, int counter)
    {
      if (y <= 0)
        return 0;
      
      if (y == 1)
        return x;
      
      if (y & 0x1)
        return x + multiply(x, y - 1, 0);
      
      if (counter + counter <= y)
        return multiply(x + x, y >> 1, counter + counter);
      else
        return x + multiply(x, y - counter, 0);
    }
    
    int squared(int number)
    {
      return multiply(number, number, 0);
    }
    
    • int sqauring (int num)
    • inline int multiply(int x, int y, int counter)
    • {
    • int times ;
    • times = num ;
    • int squared ;
    • squared = 0;
    • for (int i = 0 ; i <times ; i++ )
    • {
    • squared = squared + num ;
    • }
    • return squared ;
    • }
    • if (y <= 0)
    • return 0;
    • if (y == 1)
    • return x;
    • if (y & 0x1)
    • return x + multiply(x, y - 1, 0);
    • if (counter + counter <= y)
    • return multiply(x + x, y >> 1, counter + counter);
    • else
    • return x + multiply(x, y - counter, 0);
    • }
    • int squared(int number)
    • {
    • return multiply(number, number, 0);
    • }
Code
Diff
  • template< class T >
    void Swap( T& a, T& b ) 
    {
      a = (b - a) + (b = a);
    }
    • #include <algorithm>
    • #include <math.h>
    • template< class T >
    • void Swap( T& a, T& b )
    • {
    • std::swap(a, b);
    • a = (b - a) + (b = a);
    • }