From 5bf1c9753eb3bfde8a8a35a1316ff17ab7344478 Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 01:47:38 +0100 Subject: [PATCH] multiplication by odd --- src/multiplication.c | 9 +++++++++ src/multiplication.h | 1 + 2 files changed, 10 insertions(+) diff --git a/src/multiplication.c b/src/multiplication.c index e222e4d..e8e4602 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -112,5 +112,14 @@ int multiply_by_prime_and_its_square(int num, int prime) { return num * (prime + square (prime)); } +int multiply_by_odd(int num, int factor) { + int result = 0; + for (int i = 0; i < factor; ++i) { + result += num; + } + return result; +} + + diff --git a/src/multiplication.h b/src/multiplication.h index bd20e4a..ff24d5e 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -18,6 +18,7 @@ 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); #endif // MULTIPLICATION_H