Trying to write a program to implement Euler's Algorithm????
Mostra commenti meno recenti
I am trying to write a program to implement Euler's algorithm. I know that the greatest common divisor of (a,b,c) = gcd(gcd(a,b),c). I also want to write another program to compute the gcd of three natural numbers. I am having trouble doing this though. Here is what I know, that a = b*(quotient q) + remainder(r), where a>b and b>r, so that to find the gcd(a,b) I could replace a and b by b and r and repeat the process. The successive remainders get smaller until I eventually get r = 0. I just simply am confused on how to go about writing a program for this.
4 Commenti
Reelz
il 22 Apr 2012
Geoff
il 22 Apr 2012
Create a function to compute GCD of 2 numbers:
function [g] = gcd(a,b)
Put your code in there and make it work.
Like you already said, gcd(a,b,c) is the same as gcd(gcd(a,b),c)
Reelz
il 23 Apr 2012
Geoff
il 23 Apr 2012
Eh?? What are the other two outputs. I understand you want to compute GCD(a,b,c). Is that correct? If so, read my last comment. Make a function to compute GCD of two numbers. I don't see any function definitions in your code.
Risposte (1)
Geoff
il 18 Apr 2012
0 voti
Have you considered doing a google for the Euclidean Algorithm?
Try the very first search result =P
Halfway down the page, there's very concise pseudocode.
Categorie
Scopri di più su Resizing and Reshaping Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!