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

can a union be self-referenced?

1 Answers  


Write a C Program to display the following menu: Menu 1. Display 2. Copy 3. Append 4. Exit Accept the choice (1-4) from the user, and perform the following tasks: Choice 1: Accept a file name from the user and display the file on screen Choice 2: Accept two file names, and copy first file to the second Choice 3: Accept two file names, and append second file to the first file Choice 4: Terminate the program

1 Answers   Accenture, Concor, DMU, Satyam, Syntel, Tora,


c program for searching a student details among 10 student details

0 Answers  


n=7623 { temp=n/10; result=temp*10+ result; n=n/10 }

7 Answers   Wipro,


Expand the following LKB BKL FFG

0 Answers  






what is pointer ?

10 Answers   Kernex Micro Systems,


when will be evaluated as true/ if(x==x==x) a) x=1; b) x=0; c) x=-1; d) none

7 Answers   HCL,


How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters?

2 Answers  


Read N characters in to an array . Use functions to do all problems and pass the address of array to function. 2. Enter alphanumeric characters and form 2 array alphaets and digits.Also print the count of each array.

0 Answers  


print ur name without using any semicolon in c/c++....

21 Answers   Bosch, TCS, Wipro,


program to get the remainder and quotant of given two numbers with out using % and / operators?

10 Answers   College School Exams Tests, IBM,


What is console in c language?

0 Answers  


Categories