diff --git a/src/multiplication.c b/src/multiplication.c index 1832133..d6ba3fa 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -12,30 +12,30 @@ double square(double x) { return x * x; } -int multiply_three_integers(int a, int b, int c) { +int multi_three_integers(int a, int b, int c) { return a * b * c; } -int multiply_left_shift(int a, int b) { +int multi_left_shift(int a, int b) { return a << b; } -int multiply_right_shift(int a, int b) { +int multi_right_shift(int a, int b) { return a >> b; } -int multiply_by_ten(int a) { +int multi_by_ten(int a) { return a * 10; } -float multiply_by_percentage(float num, float percentage) { +float multi_by_percentage(float num, float percentage) { return num * (percentage / 100); } -int multiply_by_random(int num) { +int multi_by_random(int num) { int random_factor = random_factor % 10 + 1; return num * random_factor; } -int multiply_string(const char* str, int factor) { +int multi_string(const char* str, int factor) { int len = strlen(str); int result = 0; for (int i = 0; i < len; i++) { @@ -44,11 +44,11 @@ int multiply_string(const char* str, int factor) { return result; } -int multiply_by_sum(int num1, int num2) { +int multi_by_sum(int num1, int num2) { return num1 * (num2 + 1); } -int multiply_using_two_complements(int num1, int num2) { +int multi_using_two_complements(int num1, int num2) { int result = 0; while (num1 != 0) { if (num1 & 1) { @@ -60,11 +60,11 @@ int multiply_using_two_complements(int num1, int num2) { return result; } -int multiply_by_even(int num, int factor) { +int multi_by_even(int num, int factor) { return (num >> 1) << (factor + 1); } -int multiply_using_lookup_table(int num1, int num2) { +int multi_using_lookup_table(int num1, int num2) { int lookup_table[10][10] = { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, @@ -80,7 +80,7 @@ int multiply_using_lookup_table(int num1, int num2) { return lookup_table[num1][num2]; } -int multiply_using_logical_operations(int num1, int num2) { +int multi_using_logical_operations(int num1, int num2) { int result = 0; while (num2) { if (num2 & 1) { @@ -92,15 +92,15 @@ int multiply_using_logical_operations(int num1, int num2) { return result; } -int multiply_using_modulo(int num1, int num2, int modulo) { +int multi_using_modulo(int num1, int num2, int modulo) { return (num1 % modulo) * (num2 % modulo) % modulo; } -int multiply_by_prime(int num, int prime) { +int multi_by_prime(int num, int prime) { return num * (prime - 1) + num; } -int multiply_using_increment(int num1, int num2) { +int multi_using_increment(int num1, int num2) { int result = 0; for (int i = 0; i < num2; ++i) { result += num1; @@ -108,11 +108,11 @@ int multiply_using_increment(int num1, int num2) { return result; } -int multiply_by_prime_and_its_square(int num, int prime) { +int multi_by_prime_and_its_square(int num, int prime) { return num * (prime + square (prime)); } -int multiply_by_odd(int num, int factor) { +int multi_by_odd(int num, int factor) { int result = 0; for (int i = 0; i < factor; ++i) { result += num; @@ -120,7 +120,7 @@ int multiply_by_odd(int num, int factor) { return result; } -int multiply_using_binary_enumeration(int num1, int num2) { +int multi_using_binary_enumeration(int num1, int num2) { int result = 0; while (num1 && num2) { if (num2 & 1) { @@ -132,17 +132,17 @@ int multiply_using_binary_enumeration(int num1, int num2) { return result; } -int multiply_using_differences(int num1, int num2) { +int multi_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; } -int multiply_recursive_optimized(int num1, int num2) { +int multi_recursive_optimized(int num1, int num2) { if (num2 == 0) { return 0; } - int result = multiply_recursive_optimized(num1, num2 >> 1); + int result = multi_recursive_optimized(num1, num2 >> 1); result <<= 1; if (num2 & 1) { result += num1; @@ -150,7 +150,7 @@ int multiply_recursive_optimized(int num1, int num2) { return result; } -int multiply_octal_numbers(int num1, int num2) { +int multi_octal_numbers(int num1, int num2) { int result = 0; while (num2 != 0) { if (num2 & 1) { @@ -163,7 +163,7 @@ int multiply_octal_numbers(int num1, int num2) { return result; } -int multiply_hex_numbers(int num1, int num2) { +int multi_hex_numbers(int num1, int num2) { int result = 0; while (num2 != 0) { if (num2 & 1) { @@ -175,7 +175,7 @@ int multiply_hex_numbers(int num1, int num2) { return result; } -int multiply_exponentiation(int base, int exponent) { +int multi_exponentiation(int base, int exponent) { int result = 1; while (exponent > 0) { if (exponent & 1) { @@ -187,15 +187,15 @@ int multiply_exponentiation(int base, int exponent) { return result; } -int multiply_by_euler_prime(int num) { +int multi_by_euler_prime(int num) { return (num << 1) + (num << 2) - num; } -int fibonacci_multiply(int num, int fib) { +int fibonacci_multi(int num, int fib) { return num * fib; } -int repeated_division_multiply(int num1, int num2) { +int repeated_division_multi(int num1, int num2) { int result = 0; while (num1 > 0) { if (num1 % 2 == 1) { @@ -207,11 +207,11 @@ int repeated_division_multiply(int num1, int num2) { return result; } -int bernoulli_multiply(int num, int bernoulli) { +int bernoulli_multi(int num, int bernoulli) { return num * bernoulli; } -float power_multiply(float base, int exponent) { +float power_multi(float base, int exponent) { float result = 1.0; for (int i = 0; i < exponent; i++) { result *= base; @@ -219,7 +219,7 @@ float power_multiply(float base, int exponent) { return result; } -int bitwise_multiply(int num1, int num2) { +int bitwise_multi(int num1, int num2) { int result = 0; while (num1) { if (num1 & 1) { @@ -231,7 +231,7 @@ int bitwise_multiply(int num1, int num2) { return result; } -int karatsuba_multiply(int num1, int num2) { +int karatsuba_multi(int num1, int num2) { // Base case: If numbers are less than 10, return their product directly if (num1 < 10 || num2 < 10) { return num1 * num2; @@ -247,9 +247,9 @@ int karatsuba_multiply(int num1, int num2) { int d = num2 % (int)pow(10, m2); // Calculate intermediate products - int ac = karatsuba_multiply(a, c); - int bd = karatsuba_multiply(b, d); - int ad_bc = karatsuba_multiply(a + b, c + d) - ac - bd; + int ac = karatsuba_multi(a, c); + int bd = karatsuba_multi(b, d); + int ad_bc = karatsuba_multi(a + b, c + d) - ac - bd; // Calculate the final result return ac * (int)pow(10, 2 * m2) + ad_bc * (int)pow(10, m2) + bd; diff --git a/src/multiplication.h b/src/multiplication.h index 8653b4a..2e9abdb 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -2,36 +2,37 @@ #define MULTIPLICATION_H extern double multi(double ein1, double ein2); double square(double x); -int multiply_three_integers(int a, int b, int c); -int multiply_left_shift(int a, int b); -int multiply_right_shift(int a, int b); -int multiply_by_ten(int a); -float multiply_by_percentage(float num, float percentage); -int multiply_by_random(int num); -int multiply_string(const char* str, int factor); -int multiply_by_sum(int num1, int num2); -int multiply_using_two_complements(int num1, int num2); -int multiply_by_even(int num, int factor); -int multiply_using_lookup_table(int num1, int num2); -int multiply_using_logical_operations(int num1, int num2); -int multiply_using_modulo(int num1, int num2, int modulo); -int multiply_by_prime(int num, int prime); -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); -int multiply_recursive_optimized(int num1, int num2); -int multiply_octal_numbers(int num1, int num2); -int multiply_hex_numbers(int num1, int num2); -int multiply_exponentiation(int base, int exponent); -int multiply_by_euler_prime(int num); -int fibonacci_multiply(int num, int fib); -int repeated_division_multiply(int num1, int num2); -int bernoulli_multiply(int num, int bernoulli); -float power_multiply(float base, int exponent); -int bitwise_multiply(int num1, int num2); -int karatsuba_multiply(int num1, int num2); +int multi_three_integers(int a, int b, int c); +int multi_left_shift(int a, int b); +int multi_right_shift(int a, int b); +int multi_by_ten(int a); +float multi_by_percentage(float num, float percentage); +int multi_by_random(int num); +int multi_string(const char* str, int factor); +int multi_by_sum(int num1, int num2); +int multi_using_two_complements(int num1, int num2); +int multi_by_even(int num, int factor); +int multi_using_lookup_table(int num1, int num2); +int multi_using_logical_operations(int num1, int num2); +int multi_using_modulo(int num1, int num2, int modulo); +int multi_by_prime(int num, int prime); +int multi_using_increment(int num1, int num2); +int multi_by_prime_and_its_square(int num, int prime); +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_recursive_optimized(int num1, int num2); +int multi_octal_numbers(int num1, int num2); +int multi_hex_numbers(int num1, int num2); +int multi_exponentiation(int base, int exponent); +int multi_by_euler_prime(int num); +int fibonacci_multi(int num, int fib); +int repeated_division_multi(int num1, int num2); +int bernoulli_multi(int num, int bernoulli); +float power_multi(float base, int exponent); +int bitwise_multi(int num1, int num2); +int karatsuba_multi(int num1, int num2); +