The Greatest Common Divisor(GCD) of two or more numbers is the largest non-zero positive number by which all the given numbers are divisible. For example, the GCD of 8 and 12 is 4.
The Least Common Multiple (LCM) or Smallest Common Multiple of two or more numbers is the smallest non-zero positive integer that is divisible by all the given numbers. For example, LCM of 4 and 6 is 12.
The relation between GCD and LCM is
Product of numbers = GCD * LCM
#include <stdio.h>
int main()
{
int a,a1,b,b1,c,gcd,lcm;
printf("Enter First Number : ");
scanf("%d",&a);
printf("Enter Second Number : ");
scanf("%d",&b);
a1=a;
b1=b;
if(a > b)
{
c=a;
a=b;
b=c;
}
while(b%a!=0)
{
c=b%a;
b=a;
a=c;
}
gcd=a;
lcm=(a1*b1)/gcd;
printf("GCD is %d\n",gcd);
printf("LCM is %d\n",lcm);
}
Output
========
Enter First Number : 25
Enter Second Number : 15
GCD is 5
LCM is 75