The H.C.F. defines the greatest factor present in between given two or more numbers, whereas L.C.M. defines the least number which is exactly divisible by two or more numbers.
Flowchart
PROGRAM
#include <stdio.h>
#include <conio.h>
void main()
{
int x, y, x1, x2, lcm, hcf;
printf("enter a values: ");
scanf("%d \n %d", &x1, &x2);
x = x1;
y = x2;
while(x1 != x2)
{
if(x1>x2)
{
x1 = x1-x2;
/*
60-24 = 36
36-24 = 12
*/
}
else
{
x2 = x2-x1;
/*
24-12 = 12
12-12= 0(HCF 12)
*/
}
}
printf("the GCD/ HCF is %d \n", x1);
hcf = x1;
lcm = (x*y)/ hcf;
printf("the LCM is %d \n", lcm);
getch();
}
OUTPUT
Enter any two value to calculate HCF & LCM values: 36 24
The GCD/ HCF is 12.
The LCM is 72.
0 Comments