Skip to content

Commit

Permalink
Update nwdNww.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
PancernyJez authored Jun 27, 2024
1 parent 017b888 commit 2fc5f48
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions homework/nwd-nnw/nwdNww.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
#pragma once

int NWD(int lhs, int rhs) {
// TODO: Implement me :)
int dzielnik {1};
int cos;
if (lhs == 0 || rhs == 0) {
return -1;
}
while (dzielnik < abs(lhs) || dzielnik < abs(rhs)) {
if (lhs % dzielnik == 0 && rhs % dzielnik == 0) {
cos = dzielnik;
dzielnik++;
} else if (lhs % dzielnik != 0 || rhs % dzielnik != 0) {
dzielnik++;
} else
return -1;
}
return cos;
}

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

0 comments on commit 2fc5f48

Please sign in to comment.