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 is a macro?
What is a function simple definition?
Why enum is used in c?
What is floating point constants?
What are the different types of control structures?
write a program that reads lines(using getline), converts each line to an integer using atoi, and computes the average of all the numbers read. also compute the standard deviation.
Write a Program to find whether the given number or string is palindrome.
What the different types of arrays in c?
Is the exit() function same as the return statement? Explain.
Is fortran still used today?
What are Macros? What are its advantages and disadvantages?
write a program to find out prime number using sieve case?
List at least 10 sorting methods indicating their average case complexity, worst case complexity and best case complexity.
what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;
What is use of integral promotions in c?