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
What are the __date__ and __time__ preprocessor commands?
What is double pointer?
Explain built-in function?
write a program to find out prime number using sieve case?
what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above
How can I remove the trailing spaces from a string?
What are the uses of a pointer?
Is swift based on c?
What are the advantages of external class?
Please send me WIPRO technical question to my mail ID.. its nisha_g28@yahoo.com please its urgent
Explain what header files do I need in order to define the standard library functions I use?
what is the c source code for the below output? 5555555555 4444 4444 333 333 22 22 1 1 22 22 333 333 4444 4444 5555555555
Why array is used in c?
Which is best linux os?
what is the structure pointer?