Tux Education Our New Education Channel Please Share And Subscribe It...

/* LCM Program In C With Two Numbers (Other Logic) */


// Compiler : Dev-C++ 4.9.9.2

#include<stdio.h>

int lcm(int, int);

int main()
{
    int a,b,l;
    
    printf("\t\t\tNumbers Should Be Positive...\n\nA : ");
    scanf("%d",&a);
    printf("B : ");
    scanf("%d",&b);
    
    if(a>b)
    l=lcm(a,b);
    else
    l=lcm(b,a);
    
    printf("LCM : %d",l);
    
    getch();
    return 0;
}

int lcm(int a, int b)
{
    int temp=a;
    
    while(1)
    {
            if(temp%b == 0 && temp%a == 0)
            break;
            
            temp++;
    }
    
    return temp;
}

Post a Comment