File tree 1 file changed +11
-0
lines changed
chapters/fundamental_algorithms/euclidean_algorithm
1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -217,6 +217,8 @@ document.write(euclid_sub(128*12, 128*77) + "<br>");
217
217
218
218
def euclid_mod (a , b ):
219
219
220
+ a = abs (a)
221
+ b = abs (b)
220
222
temp = 0
221
223
222
224
while b > 0 :
@@ -228,6 +230,9 @@ def euclid_mod(a, b):
228
230
229
231
def euclid_sub (a , b ):
230
232
233
+ a = abs (a)
234
+ b = abs (b)
235
+
231
236
while a != b:
232
237
if a > b:
233
238
a = a - b
@@ -380,6 +385,9 @@ public static void main(String[] args) {
380
385
}
381
386
382
387
public static int euclidSub(int a, int b) {
388
+ a = Math . abs(a);
389
+ b = Math . abs(b);
390
+
383
391
while (a != b) {
384
392
if (a > b) {
385
393
a -= b;
@@ -392,6 +400,9 @@ public static int euclidSub(int a, int b) {
392
400
}
393
401
394
402
public static int euclidMod(int a, int b) {
403
+ a = Math . abs(a);
404
+ b = Math . abs(b);
405
+
395
406
while (b != 0 ){
396
407
int temp = b;
397
408
b = a % b;
You can’t perform that action at this time.
0 commit comments