From 798be4d82c735601f7506c4e2d05754c68a1201a Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 01:24:25 +0100 Subject: [PATCH] multiplication using modulo --- src/multiplication.c | 4 ++++ src/multiplication.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/multiplication.c b/src/multiplication.c index 06056de..a162d6b 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -92,5 +92,9 @@ int multiply_using_logical_operations(int num1, int num2) { return result; } +int multiply_using_modulo(int num1, int num2, int modulo) { + return (num1 % modulo) * (num2 % modulo) % modulo; +} + diff --git a/src/multiplication.h b/src/multiplication.h index b242c9b..a0d92dd 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -14,6 +14,7 @@ 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); #endif // MULTIPLICATION_H