Skip to content

Commit

Permalink
Create lcm.m
Browse files Browse the repository at this point in the history
This function calculates the lcm of two numbers.
  • Loading branch information
KaushalDevrari authored Oct 9, 2020
1 parent 6f129b8 commit c6ff92f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions algorithms/maths/lcm.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
% function to calculate lcm of two number a and b using gcd of two numbers.

function [ret] = lcm(a, b)
if b == 0
re = a;
ret=(a*b)/re; % i.e zero

else
re = gcd(b, mod(a, b));
ret=(a*b)/re;
end

0 comments on commit c6ff92f

Please sign in to comment.