Ask your own question, for FREE!
Mathematics 8 Online
OpenStudy (anonymous):

anyone know an algorithm to find the lcm of two numbers?

OpenStudy (anonymous):

int lcm(int m, int n) { // TODO }

OpenStudy (zarkon):

find the gcd(a,b) using the division alg

OpenStudy (zarkon):

lcm(a,b)=a*b/gcd(a,b)

OpenStudy (anonymous):

yeah: int gcd(int a, int b) { while (a % b != 0) { temp = a; a = b; b = a % temp; } return b; }

OpenStudy (anonymous):

thanks

OpenStudy (anonymous):

int lcm(int m, int n) { while cont { i = i + 1 if m*i == n*i break

OpenStudy (anonymous):

int lcm(int a, int b) { return (a * b)/gcd(a, b); }

OpenStudy (anonymous):

man am i ignorant. what language is that?

OpenStudy (anonymous):

C

OpenStudy (anonymous):

ah ok. in my next life...

OpenStudy (anonymous):

in python it's even better: def gcd(a,b): while a%b: a,b = b, a%b return b lcm = lambda x,y: x*y/gcd(x,y)

OpenStudy (anonymous):

I dislike the non-structured nature of Python. Fortran is where it is at, especially for us engineers.

OpenStudy (anonymous):

Why do engineers like FORTRAN so much? I happened to see an open Chem. E. textbook and it's full of FORTRAN code :-D

OpenStudy (anonymous):

function lcm(a, b) return a / gcd(a, b) * b function gcd(a, b) if (b != 0) return gcd(b, a % b) else return a

OpenStudy (anonymous):

Cause it was designed by us for us. It's original purpose was a high-level language for the purpose of numerical and scientific calculations. I mainly do all my computational work in MATLAB as it has great functions and objects already built in. It's also great at solving differential equations.

OpenStudy (anonymous):

MATLAB is great for numerical computing :-D

OpenStudy (anonymous):

so no one uses FORTRAN? all engineers use MATLAB or Octave

OpenStudy (anonymous):

Nuclear Engineers take a FORTRAN class at Texas A&M. All other disciplines take a MATLAB class. I think MATLAB is displacing the use of FORTRAN. One of my older profs uses FORTRAN for everything, but as a student, we all use MATLAB.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!