Least Common Multiple (LCM)

Given two numbers the task is to find the Least Common Multiple or Lowest Common Multiple.

Example: 6 and 15 have LCM of 30.

Here instead of Prime Factorization method we first calculate the GCD of 6 and 15 and then use formula LCM = (x*y)÷GCD. Where ‘x’ and ‘y’ are two numbers.

C
#include <stdio.h>
int main() 
{
    int n1=0,n2=0,min=0,gcd=0,lcm=0;
    printf("Enter first number: ");
    scanf("%d",&n1);
    printf("Enter second number: ");
    scanf("%d",&n2);
    min=(n1<=n2)?n1:n2;
    for(int i=1;i<=min;i++)
    {
        if(n1%i==0&&n2%i==0)
        {
            gcd=i;
        }
    }
    lcm=(n1*n2)/gcd;
    printf("LCM of %d and %d is: %d",n1,n2,lcm);
    return 0;
}
C