-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
017b888
commit 2885484
Showing
1 changed file
with
16 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|