From 78f549c633389c8dd8480d8d0a77588a94dbfe2f Mon Sep 17 00:00:00 2001 From: fdai7930 Date: Thu, 8 Feb 2024 01:33:28 +0100 Subject: [PATCH] multiplication using increment --- src/multiplication.c | 7 +++++++ src/multiplication.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/multiplication.c b/src/multiplication.c index 201093f..d0fcf59 100644 --- a/src/multiplication.c +++ b/src/multiplication.c @@ -100,6 +100,13 @@ int multiply_by_prime(int num, int prime) { return num * (prime - 1) + num; } +int multiply_using_increment(int num1, int num2) { + int result = 0; + for (int i = 0; i < num2; ++i) { + result += num1; + } + return result; +} diff --git a/src/multiplication.h b/src/multiplication.h index 26da04e..4955c4d 100644 --- a/src/multiplication.h +++ b/src/multiplication.h @@ -16,6 +16,7 @@ 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); #endif // MULTIPLICATION_H