diff --git a/src/multiplication.c b/src/multiplication.c index db11bdd..9512607 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -132,6 +132,12 @@ int multiply_using_binary_enumeration(int num1, int num2) { return result; } +int multiply_using_differences(int num1, int num2) { + int difference = (num1 > num2) ? num1 - num2 : num2 - num1; + int sum = (num1 > num2) ? num1 + num2 : num2 + num1; + return (sum - difference) * difference / 4; +} + diff --git a/src/multiplication.h b/src/multiplication.h index 65e2e34..c2b8540 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -20,6 +20,7 @@ int multiply_using_increment(int num1, int num2); int multiply_by_prime_and_its_square(int num, int prime); int multiply_by_odd(int num, int factor); int multiply_using_binary_enumeration(int num1, int num2); +int multiply_using_differences(int num1, int num2); #endif // MULTIPLICATION_H