## Search This Blog

### #Day88-LCM of Two Number

Write a code to Find LCM of two Number
LCM(12,30)=60

Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.

Matlab code

function lcmvalue=lcmoftwonumbers(a,b)

gcd=gcfoftwonumbers(a,b);

lcmvalue=(a*b)/gcd;

end

function num_gcf=gcfoftwonumbers(a,b)

if a>b

max=a;

min=b;

else

max=b;

min=a;

end

rem=mod(max,min);

if rem==0

num_gcf=min;

else

while rem>=1

min_copy=rem;

rem=mod(min,rem);

min=min_copy;

end

num_gcf=min_copy;

end

Sample Input and output

> lcmoftwonumbers(12,30)

ans =

60

>> lcmoftwonumbers(15,10)

ans =

30

>> lcmoftwonumbers(71,63)

ans =

4473

>> lcmoftwonumbers(71,23)

ans =

1633

Live Support: t.me/matlabirawen

#### 1 comment:

1. Really fine and interesting informative article. I used to be looking for this kind of advice and enjoyed looking over this one. Thanks for sharing. Thank you for sharing.Learn Ethical Hacking Course in Bangalore

MATLAB  