Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions homework/nwd-nnw/nwdNww.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
#pragma once

int NWD(int lhs, int rhs) {
// TODO: Implement me :)
return -1;
if (lhs < 0)
lhs = lhs * (-1);
else if (rhs < 0)
rhs = rhs * (-1);

//--------------------------------
if (lhs == 0) {
return rhs;
} else if (rhs == 0) {
return lhs;
}
//--------------------------------
if (lhs == rhs) {
return lhs;
}
//--------------------------------
if (lhs > rhs) {
return NWD(lhs - rhs, rhs);
} else {
return NWD(lhs, rhs - lhs);
}
}

int NWW(int lhs, int rhs) {
// TODO: Implement me :)
return -1;
if (lhs == 0 || rhs == 0) {
return 0;
} else {
auto result = lhs / NWD(lhs, rhs) * rhs;
if (result < 0) {
return (result * (-1));
} else
return result;
}
}