Mercurial > octave
diff scripts/elfun/lcm.m @ 904:3470f1e25a79
[project @ 1994-11-09 21:22:15 by jwe]
author | jwe |
---|---|
date | Wed, 09 Nov 1994 21:22:15 +0000 |
parents | 6544b83ef9e9 |
children | 9fc405c8c06c |
line wrap: on
line diff
--- a/scripts/elfun/lcm.m Wed Nov 09 20:02:47 1994 +0000 +++ b/scripts/elfun/lcm.m Wed Nov 09 21:22:15 1994 +0000 @@ -1,29 +1,29 @@ function l = lcm (a, ...) + +# lcm (a) returns the least common multiple of the entries of the +# integer vector a. +# lcm (a1, ..., ak) is the same as lcm([a1, ..., ak]). - # lcm (a) returns the least common multiple of the entries of the - # integer vector a. - # lcm (a1, ..., ak) is the same as lcm([a1, ..., ak]). - - # Written by KH (Kurt.Hornik@ci.tuwien.ac.at) on Sep 16, 1994 - # Copyright Dept of Statistics and Probability Theory TU Wien +# Written by KH (Kurt.Hornik@ci.tuwien.ac.at) on Sep 16, 1994 +# Copyright Dept of Statistics and Probability Theory TU Wien if (nargin > 1) va_start; - for k=2:nargin; - a = [a, va_arg()]; + for k = 2:nargin; + a = [a, va_arg ()]; endfor endif - if (round(a) != a) - error("lcm: all arguments must be integer"); + if (round (a) != a) + error ("lcm: all arguments must be integer"); endif - if (any(a) == 0) + if (any (a) == 0) l = 0; else - a = abs(a); - l = a(1); - for k=1:(length(a)-1) + a = abs (a); + l = a (1); + for k = 1:(length (a) - 1) l = l * a(k+1) / gcd(l, a(k+1)); endfor endif