Skip to content

Commit

Permalink
adding works
Browse files Browse the repository at this point in the history
  • Loading branch information
VeniGogniti committed Jul 1, 2024
1 parent 3c8b812 commit 31b6249
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions homework/nwd-nnw/nwdNww.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
#pragma once
#include <iostream>
#include <cstdlib>

int NWD(int lhs, int rhs) {
// TODO: Implement me :)
return -1;
lhs = std::abs(lhs);
rhs = std::abs(rhs);

if (lhs == 0) {
return rhs;
}

if (rhs == 0) {
return lhs;
}

while (lhs != rhs) {
if (lhs > rhs) {
lhs = lhs - rhs;
} else {
rhs = rhs - lhs;
}
std::cout << rhs << ", " << lhs << std::endl;
}

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)) * std::abs(rhs);
}

0 comments on commit 31b6249

Please sign in to comment.