Skip to content

Commit c6ff92f

Browse files
Create lcm.m
This function calculates the lcm of two numbers.
1 parent 6f129b8 commit c6ff92f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

algorithms/maths/lcm.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
% function to calculate lcm of two number a and b using gcd of two numbers.
2+
3+
function [ret] = lcm(a, b)
4+
if b == 0
5+
re = a;
6+
ret=(a*b)/re; % i.e zero
7+
8+
else
9+
re = gcd(b, mod(a, b));
10+
ret=(a*b)/re;
11+
end

0 commit comments

Comments
 (0)