Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

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

+3 votes
asked Mar 12, 2023 by subas (150 points)

4 Answers

0 votes
answered Mar 12, 2023 by Peter Minarik (82,920 points)
edited Mar 13, 2023 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

0 votes
answered Mar 12, 2023 by bishnu mahto (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;

}
commented Apr 8, 2023 by KEDARI LAKSHMI VANDANA (100 points)
Here hcf=i is the bug i thought so!!!
0 votes
answered Mar 13, 2023 by Fatima Suleiman Atta (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;

}
0 votes
answered Mar 15, 2023 by SiRius (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;
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...