Skip to content

Commit

Permalink
Add NWD and NWW implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Coder06-dev committed Jan 27, 2025
1 parent 017b888 commit 2885484
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions homework/nwd-nnw/nwdNww.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
#pragma once

int NWD(int lhs, int rhs) {
// TODO: Implement me :)
return -1;
int x = 0;
lhs = abs(lhs);
rhs = abs(rhs);
while (rhs) {
x = rhs;
rhs = lhs % rhs;
lhs = x;
}
return lhs;
}

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

0 comments on commit 2885484

Please sign in to comment.