Skip to content

Commit 7420e4c

Browse files
authored
Merge pull request #15 from Butt4cak3/euclid_negative
Negative number support for the Java and Python examples for Euclid's Algorithm
2 parents eaf0dbe + 8adf883 commit 7420e4c

File tree

1 file changed

+11
-0
lines changed
  • chapters/fundamental_algorithms/euclidean_algorithm

1 file changed

+11
-0
lines changed

chapters/fundamental_algorithms/euclidean_algorithm/euclidean.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ document.write(euclid_sub(128*12, 128*77) + "<br>");
217217

218218
def euclid_mod(a, b):
219219

220+
a = abs(a)
221+
b = abs(b)
220222
temp = 0
221223

222224
while b > 0:
@@ -228,6 +230,9 @@ def euclid_mod(a, b):
228230

229231
def euclid_sub(a, b):
230232

233+
a = abs(a)
234+
b = abs(b)
235+
231236
while a != b:
232237
if a > b:
233238
a = a - b
@@ -380,6 +385,9 @@ public static void main(String[] args) {
380385
}
381386

382387
public static int euclidSub(int a, int b) {
388+
a = Math.abs(a);
389+
b = Math.abs(b);
390+
383391
while (a != b) {
384392
if (a > b) {
385393
a -=b;
@@ -392,6 +400,9 @@ public static int euclidSub(int a, int b) {
392400
}
393401

394402
public static int euclidMod(int a, int b) {
403+
a = Math.abs(a);
404+
b = Math.abs(b);
405+
395406
while (b != 0){
396407
int temp = b;
397408
b = a % b;

0 commit comments

Comments
 (0)