how we do lcm of two no using c simple if while or for
statement

Answer Posted / aditya goel

#include<stdio.h>
#include<conio.h>
main()
{
int lcm=1,a,b,c,d,x;
clrscr():
printf("Enter any two numbers:\n");
scanf("%d %d",&a,&b);
c=a;d=b;
x=(a<b)?a:b;
for(i=2;i<=x;i++)
{
if ((a%i==0) && (b%i==0))
{
lcm=lcm*i;c=c/i;d=d/i;
}
else if (a%i==0)
{
lcm=lcm*i;c=c/i
}
else if (b%i==0)
{
lcm=lcm*i;d=d/i;
}
}
lcm=lcm*c*d;
printf("lcm is %d",lcm);
getch();
}

Is This Answer Correct ?    3 Yes 13 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Compare array data type to pointer data type

605


What is strcpy() function?

662


where are auto variables stored? What are the characteristics of an auto variable?

597


typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for?

1080


What are compound statements?

633






what are the 10 different models of writing an addition program in C language?

1443


What is the g value paradox?

650


Difference between macros and inline functions? Can a function be forced as inline?

718


write a program that declares an array of 30 elements named "income" in the main functions. then cal and pass the array to a programmer-defined function named "getIncome" within the "getIncome" function, ask the user for annual income of 30 employees. then calculate and print total income on the screen using the following function: "void getIncome ( ai []);

1854


#include int main(){ int i=10; int *ptr=&i; *ptr=(int *)20; printf("%d",i); return 0; } Output: 20 can anyone explain how came the output is 20

1269


How many types of functions are there in c?

587


What is a good way to implement complex numbers in c?

600


program to find error in linklist.(i.e find whether any node point wrongly to previous nodes instead of next node)

1631


Why does notstrcat(string, "!");Work?

646


Explain how can I make sure that my program is the only one accessing a file?

635