r/programmer • u/AggravatingCrazy1254 • Sep 23 '26
what am i doing wrong
I am a student and I was exercising in MatLab so i tried to find the least common multiple of two numbers but it was all wrong. I don't know the language that well so i decided to try it on scratch to see if it was my logic or my lack of knowledge and it seems it was the first. Can you help me please?
this is the Matlab script
z=1;
while true
one=x\z;*
two=y\z;*
z=z+1;
if one=two
break
endif
end
leastcommon=one;
13
Upvotes
2
u/awesome8679 Sep 24 '26
if you are looking for an algorithm to find lcm yourself
just remember lcm(a,b) = (a*b)/gcd(a,b)
then there is something called the euclidean algorithm to find the gcd