Euclidean Algorithm (greatest common divisor)
Author |
Message |
randint
|
Posted: Wed Aug 01, 2012 8:57 pm Post subject: Euclidean Algorithm (greatest common divisor) |
|
|
Just some fun stuff......the Euclidean Algorithm for finding the greatest common divisor of 2 natural numbers, a and b
Description: |
|
Download |
Filename: |
EuclideanAlgorithm.java |
Filesize: |
1.96 KB |
Downloaded: |
444 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Panphobia
|
Posted: Sun Nov 18, 2012 3:07 pm Post subject: Re: Euclidean Algorithm (greatest common divisor) |
|
|
cant it be done simpler like this? code: | public static int gcd(int m, int n) {
if ((m % n) == 0) {
return n;
} else {
return gcd(n, m % n);
}
} |
|
|
|
|
|
|
Panphobia
|
Posted: Sun Nov 18, 2012 3:08 pm Post subject: RE:Euclidean Algorithm (greatest common divisor) |
|
|
Sorry didnt read euclidean algorithm, my bad
|
|
|
|
|
|
randint
|
Posted: Sun Nov 18, 2012 5:18 pm Post subject: RE:Euclidean Algorithm (greatest common divisor) |
|
|
Again, not that it is impossible, but recursion somehow sucks...computational complexity
|
|
|
|
|
|
|
|