From 66f28def9243cbde640b675dea56489fdd228de7 Mon Sep 17 00:00:00 2001 From: cxnnqr Date: Fri, 2 Feb 2024 15:37:44 +0100 Subject: [PATCH] added simple algorithm for getting the kgV --- src/kgV/kgV.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/kgV/kgV.c b/src/kgV/kgV.c index 857de9c..0fd539a 100644 --- a/src/kgV/kgV.c +++ b/src/kgV/kgV.c @@ -1,3 +1,19 @@ #include -int kgV(int a, int b); \ No newline at end of file +int ggT(int a, int b){ + // handles the zero cases + if(a == 0) return b; + if(b == 0) return a; + + // Euclidean algorithm with modulo for getting the ggT + while (b != 0) { + int temp = b; + b = a % b; + a = temp; + } + return a; +} + +int kgV(int a, int b){ + return a*b/ ggT(a, b); +} \ No newline at end of file