### C Program to find LCM lowest(least) Common Multiples & GCD Greatest Common Divisor

#include<stdio.h>

int GCD(int a,int b)

{

int c;

while(b > 0)

{

c = a%b;

a = b; b = c;

}

return a;

}

int main()

{

int i,a,b,LCM;

while(scanf("%d%d",&a,&b)==2)

{

LCM = (a*b) / GCD(a,b);

printf("%d\n",LCM);

}

return 0;

}

int GCD(int a,int b)

{

int c;

while(b > 0)

{

c = a%b;

a = b; b = c;

}

return a;

}

int main()

{

int i,a,b,LCM;

while(scanf("%d%d",&a,&b)==2)

{

LCM = (a*b) / GCD(a,b);

printf("%d\n",LCM);

}

return 0;

}

Input:

501 36

14 6

24 12

501 36

14 6

24 12

Output:

6012

42

24

6012

42

24

## No comments:

## Post a Comment