Skip to content

Commit

Permalink
Update nwdNww.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafal-Leszczynski authored Apr 13, 2024
1 parent 859a0c8 commit 47e4a1f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions homework/nwd-nnw/nwdNww.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
#pragma once

int NWD(int lhs, int rhs) {
if (lhs == 0 || rhs == 0) {
lhs = std::abs(lhs);
rhs = std::abs(rhs);
if (lhs == 0 && rhs == 0) {
return 0;
}
if (lhs == 0 || rhs == 0) {
return lhs + rhs;
}
if (lhs != rhs) {
return NWD(lhs > rhs ? lhs - rhs : lhs, rhs > lhs ? rhs - lhs : rhs);
}
return lhs;
}

int NWW(int lhs, int rhs) {
lhs = std::abs(lhs);
rhs = std::abs(rhs);
if (lhs == 0 || rhs == 0) {
return 0;
}
lhs = std::abs(lhs);
rhs = std::abs(rhs);
int temp = rhs * lhs;
while (lhs != rhs) {
if (lhs > rhs) {
Expand Down

0 comments on commit 47e4a1f

Please sign in to comment.