From a18d40805bf3034ab120a833a9e45181a17eaa9f Mon Sep 17 00:00:00 2001 From: TodorokiBoy Date: Thu, 21 Nov 2024 20:40:56 +0100 Subject: [PATCH] adding works --- homework/nwd-nnw/nwdNww.hpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/homework/nwd-nnw/nwdNww.hpp b/homework/nwd-nnw/nwdNww.hpp index 0491a2c9..b837d668 100644 --- a/homework/nwd-nnw/nwdNww.hpp +++ b/homework/nwd-nnw/nwdNww.hpp @@ -1,11 +1,22 @@ #pragma once int NWD(int lhs, int rhs) { - // TODO: Implement me :) - return -1; + if (lhs == 0 || rhs == 0) { + return std::abs(lhs + rhs); + } + lhs = std::abs(lhs); + rhs = std::abs(rhs); + while (rhs != 0) { + int temp = lhs; + lhs = rhs; + rhs = temp % rhs; + } + return lhs; } int NWW(int lhs, int rhs) { - // TODO: Implement me :) - return -1; + if (lhs == 0 || rhs == 0) { + return 0; + } + return std::abs(lhs / NWD(lhs, rhs) * rhs); }