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

How are structure passing and returning implemented?

0 Answers  


What are the phases in s/w developed life cycle? wat is the diff b/w stack & queue...where do we use stack

6 Answers  


Go through the following code sinippet char a[20]; a="Hello Orcale Test"; will this compile?

4 Answers   Oracle,


code for copying two strings with out strcpy() function.

6 Answers  


While(1) { } when this loop get terminate is it a infinite loop?

5 Answers  






What are pointers really good for, anyway?

0 Answers  


Write a function that accepts a sentence as a parameter, and returns the same with each of its words reversed. The returned sentence should have 1 blank space between each pair of words. Demonstrate the usage of this function from a main program. Example: Parameter: “jack and jill went up a hill” Return Value: “kcaj dna llij tnew pu a llih”

5 Answers   Mind Tree,


Can you pass an entire structure to functions?

0 Answers  


Explain how do you list files in a directory?

0 Answers  


WAP to convert text into its ASCII Code and also write a function to decode the text given?

2 Answers  


write a program for the normal snake games find in most of the mobiles.

0 Answers   Accenture, Wipro,


What is the meaning of 2d in c?

0 Answers  


Categories