Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Euclidean Algorithm (greatest common divisor)
Index -> Programming, Java -> Java Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
randint




PostPosted: 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


EuclideanAlgorithm.java
 Description:

Download
 Filename:  EuclideanAlgorithm.java
 Filesize:  1.96 KB
 Downloaded:  430 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Panphobia




PostPosted: 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




PostPosted: Sun Nov 18, 2012 3:08 pm   Post subject: RE:Euclidean Algorithm (greatest common divisor)

Sorry didnt read euclidean algorithm, my bad Very Happy
randint




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Java -> Java Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: