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 @@ -203,6 +203,8 @@ document.write(euclid_sub(128*12, 128*77) + "<br>");
203
203
204
204
def euclid_mod (a , b ):
205
205
206
+ a = abs (a)
207
+ b = abs (b)
206
208
temp = 0
207
209
208
210
while b > 0 :
@@ -214,6 +216,9 @@ def euclid_mod(a, b):
214
216
215
217
def euclid_sub (a , b ):
216
218
219
+ a = abs (a)
220
+ b = abs (b)
221
+
217
222
while a != b:
218
223
if a > b:
219
224
a = a - b
@@ -366,6 +371,9 @@ public static void main(String[] args) {
366
371
}
367
372
368
373
public static int euclidSub(int a, int b) {
374
+ a = Math . abs(a);
375
+ b = Math . abs(b);
376
+
369
377
while (a != b) {
370
378
if (a > b) {
371
379
a -= b;
@@ -378,6 +386,9 @@ public static int euclidSub(int a, int b) {
378
386
}
379
387
380
388
public static int euclidMod(int a, int b) {
389
+ a = Math . abs(a);
390
+ b = Math . abs(b);
391
+
381
392
while (b != 0 ){
382
393
int temp = b;
383
394
b = a % b;
You can’t perform that action at this time.
0 commit comments