diff --git a/C/LCMoftwonumbers.c b/C/LCMoftwonumbers.c new file mode 100644 index 0000000..faac28f --- /dev/null +++ b/C/LCMoftwonumbers.c @@ -0,0 +1,18 @@ +#include +int main() +{ + int n1, n2, minMultiple; + printf("Enter two positive integers: "); + scanf("%d %d", &n1, &n2); + minMultiple = (n1>n2) ? n1 : n2; + while(1) + { + if( minMultiple%n1==0 && minMultiple%n2==0 ) + { + printf("The LCM of %d and %d is %d.", n1, n2,minMultiple); + break; + } + ++minMultiple; + } + return 0; +} diff --git a/Python/LCMoftwonumbers.py b/Python/LCMoftwonumbers.py new file mode 100644 index 0000000..d1d934c --- /dev/null +++ b/Python/LCMoftwonumbers.py @@ -0,0 +1,16 @@ +def lcm(x, y): + if x > y: + greater = x + else: + greater = y + while(True): + if((greater % x == 0) and (greater % y == 0)): + lcm = greater + break + greater += 1 + return lcm + + +num1 = int(input("Enter first number: ")) +num2 = int(input("Enter second number: ")) +print("The L.C.M. of", num1,"and", num2,"is", lcm(num1, num2))