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



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

Answer / 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

More C Interview Questions

Combinations of fibanocci prime series

0 Answers  


without using control structures and control structures find the max and min of given 2 nos

1 Answers   HCL,


Explain the difference between getch() and getche() in c?

0 Answers  


please help me.. how to write a code of this output?? "Enter range number:"10 1 is an odd number 2 is an even numbers 3 in an odd numbers 4 " to 10" "printing all odd numbers:" 1,3,5,7,9 "printing all even numbers:" 2,4,6,8,10 "sum of all odd numbers:25 "sum of all even numbers:30 using a C Programming ARRAY pleas pleas help.. its my project ..please :(

1 Answers  


Implement a function that returns the 5th element from the end in a singly linked list of integers in one pass.

11 Answers   Microsoft,


Explain what is the advantage of a random access file?

0 Answers  


What are the types of pointers in c?

0 Answers  


Why do we use main function?

0 Answers  


how to add our own function in c library please give details.?

1 Answers   TCS,


#include<stdio.h> void main() { int a,b,c; a=b=c=1; c=++a || ++b && ++c; printf("%d\t%d\t%d",a,b,c); }

3 Answers  


Write a program to print the prime numbers from 1 to 100?

7 Answers  


what does ‘segmentation violation’ mean?

1 Answers  


Categories