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
any C program contains only one function, it must be a) void () b) main () c) message () d) abc ()
How can you convert integers to binary or hexadecimal?
What is the use of gets and puts?
What is dynamic dispatch in c++?
How to write a multi-statement macro?
What are comments and how do you insert it in a C program?
Differentiate between Macro and ordinary definition.
Which control loop is recommended if you have to execute set of statements for fixed number of times?
Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..
A c program to display count values from 0 to 100 and flash each digit for a secong.reset the counter after it reaches 100.use for loop,. pls guys hepl me.. :(
hi send me sample aptitude papers of cts?
What are the differences between new and malloc in C?
Why can't I perform arithmetic on a void* pointer?
What is queue in c?
What does the error 'Null Pointer Assignment' mean and what causes this error?