C Program to calculate the LCM of two numbers

#include<stdio.h>
int main()
{
    int a,b,max,i;
    printf("Enter the first number\n");
    scanf("%d",&a);
    printf("Enter the second number\n");
    scanf("%d",&b);
    max=a>b?a:b;
    for(i=max;i<=a*b;i=i+max)
    {
        if(i%a==0 && i%b==0)
        {
            printf("LCM of %d and %d is : %d\n",a,b,i);
            break;
        }
    }
}

Output:
C Program to calculate the LCM of two numbers

Comments