Browse Source

multiplication recursive optimized

remotes/origin/multiplication
fdai7930 11 months ago
parent
commit
d937085f04
  1. 12
      src/multiplication.c
  2. 1
      src/multiplication.h

12
src/multiplication.c

@ -138,6 +138,18 @@ int multiply_using_differences(int num1, int num2) {
return (sum - difference) * difference / 4;
}
int multiply_recursive_optimized(int num1, int num2) {
if (num2 == 0) {
return 0;
}
int result = multiply_recursive_optimized(num1, num2 >> 1);
result <<= 1;
if (num2 & 1) {
result += num1;
}
return result;
}

1
src/multiplication.h

@ -21,6 +21,7 @@ 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);
int multiply_recursive_optimized(int num1, int num2);
#endif // MULTIPLICATION_H

Loading…
Cancel
Save