From 6247b18422973d274b8fc989311376cfc9dea92e Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 12:31:16 +0100 Subject: [PATCH] repeated division multiplication fonction added --- src/multiplication.c | 14 ++++++++++++++ src/multiplication.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/multiplication.c b/src/multiplication.c index 94d6fcb..15884c2 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -195,6 +195,20 @@ int fibonacci_multiply(int num, int fib) { return num * fib; } +int repeated_division_multiply(int num1, int num2) { + int result = 0; + while (num1 > 0) { + if (num1 % 2 == 1) { + result += num2; + } + num1 >>= 1; + num2 <<= 1; + } + return result; +} + + + diff --git a/src/multiplication.h b/src/multiplication.h index 809a214..1d81954 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -27,6 +27,7 @@ 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);