Browse Source

multiplication using differences

remotes/origin/multiplication
fdai7930 11 months ago
parent
commit
924796010f
  1. 6
      src/multiplication.c
  2. 1
      src/multiplication.h

6
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;
}

1
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

Loading…
Cancel
Save