Skip to content

Negative number support for the Java and Python examples for Euclid's Algorithm #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2017
Merged
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
11 changes: 11 additions & 0 deletions chapters/fundamental_algorithms/euclidean_algorithm/euclidean.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ document.write(euclid_sub(128*12, 128*77) + "<br>");

def euclid_mod(a, b):

a = abs(a)
b = abs(b)
temp = 0

while b > 0:
Expand All @@ -214,6 +216,9 @@ def euclid_mod(a, b):

def euclid_sub(a, b):

a = abs(a)
b = abs(b)

while a != b:
if a > b:
a = a - b
Expand Down Expand Up @@ -366,6 +371,9 @@ public static void main(String[] args) {
}

public static int euclidSub(int a, int b) {
a = Math.abs(a);
b = Math.abs(b);

while (a != b) {
if (a > b) {
a -=b;
Expand All @@ -378,6 +386,9 @@ public static int euclidSub(int a, int b) {
}

public static int euclidMod(int a, int b) {
a = Math.abs(a);
b = Math.abs(b);

while (b != 0){
int temp = b;
b = a % b;
Expand Down