+ 5
Euclidean Algoritmh
With this code you can find the largest common divisor of two numbers. This code was made and inspired by the Euclidean Algorithm, I hope you enjoy it, and will like to read what you think. https://code.sololearn.com/c4mBLbUzDPPD/?ref=app
8 Respostas
+ 6
thanks bro!
+ 6
yes I will 😋
+ 3
Woo is very true. I did not take that into account. Thanks for reporting the flaw. I'll fix it
+ 1
Nice, I recently saw this algorithm :)
+ 1
I just posted under My Codes Euclid's Algorithm in Java if you want to give it a look. 😀
0
i started a design and analysis of algorithms course this is the first algo we looked at Hahah 💻✌
0
Hi. Sorry, your program is nice but it has a bug. For example if num1 = 170 and num2 = 85 then there is no output, if num1 = 45 and num2 = 72 the output is 18 instead of 9 and if num1 = 92 and num2 = 56 the output is 8 instead of 4. This is definitely not correct. The bug is in your method: you always use num2 as dividend, but in euclidean algorithm the dividend always change every step like this:
num_1 = r_0 * q_1 + r_1, with num_2 = r_0
r_0 = r_1 * q_2 + r_2
r_1 = r_2 * q_3 + r_3
...
r_n-1 = r_n * q_n+1 + 0
Then mcd = r_n
I hope it helps.
0
Hi. Did you change the code because the errors i described earlier occur: 92 and 56 -> no ouput, 45 and 72 -> 18 instead of 9 and 92 and 56 -> 8 instead of 4. Sorry.