# can someone explain me the bug here and solve the problem https://onlinegdb.com/_Yn0l8TPM

answered Mar 12 by (69,270 points)
edited Mar 13 by Peter Minarik

The bug is simple.

You do not calculate the least common multiple (LCM) of two numbers by multiplying both numbers with another 3rd number in the hopes that it will one day make them equal (it will not -- unless the 3rd number is 0 or infinity).

There are various ways to find the least common multiple. Here are some in this article.

Solve the problem: you can easily do this after you understand at least one algorithm for the least common multiple calculations. Take your best shot, try to solve the problem and share your solution if you need further assistance.

Good luck

answered Mar 12 by (140 points)
#include<stdio.h>

int main()

{

int a,b,hcf=1,lcm,i,min;

printf("enter the 1st and 2nd num");

scanf("%d %d",&a,&b);

if(a<b)

min=a;

else

min=b;

for(i=1;i<=min;i++)

{

if(a%i==0 && b%i==0)

hcf=i;

}

lcm=a8b/hcf;

printf("HCF =%d",hcf);

printf("lcm =%d",lcm);

return 0;

}
answered Mar 13 by (320 points)
#include<stdio.h>

int main()

{

int a,b,hcf=1,lcm,i,min;

printf("enter the 1st and 2nd num");

scanf("%d %d",&a,&b);

if(a<b)

min=a;

else

min=b;

for(i=1;i<=min;i++)

{

if(a%i==0 && b%i==0)

hcf=i;

}

lcm=a&b/HCF;

printf("HCF =%d",hcf);

printf("lcm =%d",lcm);

return 0;

}
answered Mar 15 by (140 points)
#include<stdio.h>

int main()

{

int a,b,hcf=1,lcm,i,min;

printf("enter the 1st and 2nd num");

scanf("%d %d",&a,&b);

if(a<b)

min=a;

else

min=b;

for(i=1;i<=min;i++)

{

if(a%i==0 && b%i==0)

hcf=i;

}

lcm=a*b/hcf;

printf("HCF =%d\n",hcf);

printf("lcm =%d",lcm);

return 0;

}

you did mistake in lcm = a8b/hcf
it should be lcm=a*b/hcf;