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
Compare array data type to pointer data type
What is strcpy() function?
where are auto variables stored? What are the characteristics of an auto variable?
typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for?
What are compound statements?
what are the 10 different models of writing an addition program in C language?
What is the g value paradox?
Difference between macros and inline functions? Can a function be forced as inline?
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 []);
#include
How many types of functions are there in c?
What is a good way to implement complex numbers in c?
program to find error in linklist.(i.e find whether any node point wrongly to previous nodes instead of next node)
Why does notstrcat(string, "!");Work?
Explain how can I make sure that my program is the only one accessing a file?