From ae3fa600fbafc4bb8a6a3966a55e632a5a98a80d Mon Sep 17 00:00:00 2001 From: Konrad Legutko Date: Wed, 16 Sep 2026 17:51:38 +0000 Subject: [PATCH 1/2] [feat] Implementation nww and nwd --- homework/nwd-nnw/nwdNww.hpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/homework/nwd-nnw/nwdNww.hpp b/homework/nwd-nnw/nwdNww.hpp index 0491a2c9..6680e9db 100644 --- a/homework/nwd-nnw/nwdNww.hpp +++ b/homework/nwd-nnw/nwdNww.hpp @@ -1,11 +1,27 @@ #pragma once +#include int NWD(int lhs, int rhs) { - // TODO: Implement me :) - return -1; + lhs = std::abs(lhs); + rhs = std::abs(rhs); + if(lhs == 0 && rhs != 0) + return rhs; + else if(lhs != 0 && rhs == 0) + return lhs; + while(lhs != rhs) + { + if(lhs > rhs) + lhs -= rhs; + else + rhs -= lhs; + } + return lhs; } int NWW(int lhs, int rhs) { - // TODO: Implement me :) - return -1; + + int nwd = NWD(lhs,rhs); + if(nwd == 0) + return 0; + return std::abs((lhs * rhs) / nwd); } From 97378d5ffb414efa39a7dbf0f6bf2ccad9d5bd53 Mon Sep 17 00:00:00 2001 From: Konrad Legutko Date: Wed, 16 Sep 2026 17:52:41 +0000 Subject: [PATCH 2/2] [refactor] formatting --- homework/nwd-nnw/nwdNww.hpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/homework/nwd-nnw/nwdNww.hpp b/homework/nwd-nnw/nwdNww.hpp index 6680e9db..17185a24 100644 --- a/homework/nwd-nnw/nwdNww.hpp +++ b/homework/nwd-nnw/nwdNww.hpp @@ -4,13 +4,12 @@ int NWD(int lhs, int rhs) { lhs = std::abs(lhs); rhs = std::abs(rhs); - if(lhs == 0 && rhs != 0) + if (lhs == 0 && rhs != 0) return rhs; - else if(lhs != 0 && rhs == 0) + else if (lhs != 0 && rhs == 0) return lhs; - while(lhs != rhs) - { - if(lhs > rhs) + while (lhs != rhs) { + if (lhs > rhs) lhs -= rhs; else rhs -= lhs; @@ -19,9 +18,8 @@ int NWD(int lhs, int rhs) { } int NWW(int lhs, int rhs) { - - int nwd = NWD(lhs,rhs); - if(nwd == 0) + int nwd = NWD(lhs, rhs); + if (nwd == 0) return 0; return std::abs((lhs * rhs) / nwd); }