Browse Source

Refactoring: remove _using from all multiplication fonctions name

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

12
src/multiplication.c

@ -47,7 +47,7 @@ int multi_string(const char* str, int factor) {
int multi_using_two_comp(int num2, int num3) {
int multi_two_comp(int num2, int num3) {
int result = 0; int result = 0;
while (num2 != 0) { while (num2 != 0) {
if (num2 & 1) { if (num2 & 1) {
@ -63,7 +63,7 @@ int multi_by_even(int num, int factor) {
return (num >> 1) << (factor + 1); return (num >> 1) << (factor + 1);
} }
int multi_using_lookup_table(int num1, int num2) {
int multi_lookup_table(int num1, int num2) {
int lookup_table[10][10] = { int lookup_table[10][10] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
@ -79,7 +79,7 @@ int multi_using_lookup_table(int num1, int num2) {
return lookup_table[num1][num2]; return lookup_table[num1][num2];
} }
int multi_using_logical_op(int num1, int num2) {
int multi_logical_op(int num1, int num2) {
int result = 0; int result = 0;
while (num2) { while (num2) {
if (num2 & 1) { if (num2 & 1) {
@ -99,7 +99,7 @@ int multi_by_prime(int num, int prime) {
return num * (prime - 2) + num; return num * (prime - 2) + num;
} }
int multi_using_increment(int num1, int num2) {
int multi_increment(int num1, int num2) {
int result = 0; int result = 0;
for (int i = 0; i < num2; ++i) { for (int i = 0; i < num2; ++i) {
result += num1; result += num1;
@ -119,7 +119,7 @@ int multi_by_odd(int num, int factor) {
return result; return result;
} }
int multi_using_binary_enumeration(int num1, int num2) {
int multi_binary_enumeration(int num1, int num2) {
int result = 0; int result = 0;
while (num1 && num2) { while (num1 && num2) {
if (num2 & 1) { if (num2 & 1) {
@ -131,7 +131,7 @@ int multi_using_binary_enumeration(int num1, int num2) {
return result; return result;
} }
int multi_using_differences(int num1, int num2) {
int multi_differences(int num1, int num2) {
int difference = (num1 > num2) ? num1 - num2 : num2 - num1; int difference = (num1 > num2) ? num1 - num2 : num2 - num1;
int sum = (num1 > num2) ? num1 + num2 : num2 + num1; int sum = (num1 > num2) ? num1 + num2 : num2 + num1;
return (sum - difference) * difference / 4; return (sum - difference) * difference / 4;

12
src/multiplication.h

@ -10,17 +10,17 @@ float multi_by_percentage(float num, float percentage);
int multi_by_random(int num); int multi_by_random(int num);
int multi_string(const char* str, int factor); int multi_string(const char* str, int factor);
int multi_using_two_comp(int num2, int num3);
int multi_two_comp(int num2, int num3);
int multi_by_even(int num, int factor); int multi_by_even(int num, int factor);
int multi_using_lookup_table(int num1, int num2);
int multi_using_logical_op(int num1, int num2);
int multi_lookup_table(int num1, int num2);
int multi_logical_op(int num1, int num2);
int multi_modulo(int num1, int num2, int modulo); int multi_modulo(int num1, int num2, int modulo);
int multi_by_prime(int num, int prime); int multi_by_prime(int num, int prime);
int multi_using_increment(int num1, int num2);
int multi_increment(int num1, int num2);
int multi_by_prime_and_its_square(int num, int prime); int multi_by_prime_and_its_square(int num, int prime);
int multi_by_odd(int num, int factor); int multi_by_odd(int num, int factor);
int multi_using_binary_enumeration(int num1, int num2);
int multi_using_differences(int num1, int num2);
int multi_binary_enumeration(int num1, int num2);
int multi_differences(int num1, int num2);
int multi_recursive_optimized(int num1, int num2); int multi_recursive_optimized(int num1, int num2);
int multi_octal_numbers(int num1, int num2); int multi_octal_numbers(int num1, int num2);
int multi_hex_numbers(int num1, int num2); int multi_hex_numbers(int num1, int num2);

Loading…
Cancel
Save