Write a Pseudo Code to fins the LCM of two given numbers
Answers were Sorted based on User's Feedback
Answer / zain
#include<iostream>
using namespace std;
int LCM(int a,int b);
int main()
{
int a,b;
cout<<" ENTER TWO NUMBER : ";
cin>>a>>b;
cout<<"\n\n LCM : "<<LCM(a,b);
system("pause");
return 0;
}
int LCM(int a,int b)
{
int n;
for(n=1;;n++)
{
if(n%a == 0 && n%b == 0)
return n;
}
}
Is This Answer Correct ? | 49 Yes | 23 No |
Answer / sudhir
int gcd(int a, int b)
{
if (a==0 && b==0) return -1;
if (b==0) return a;
return gcd(b,a%b);
}
int lcm (int a, int b)
{
return (int) (a*b)/gcd(a,b);
}
Is This Answer Correct ? | 22 Yes | 4 No |
Answer / mohit
#include <stdio.h>
main()
{
int a,b,n=2,res=1;
printf("Enter two integers : ");
scanf("%d %d",&a,&b);
while((a!=1)||(b!=1))
{
if((a%n==0)&&(b%n==0))
{
a/=n;
b/=n;
res*=n;
}
else if((a%n==0)&&(b%n!=0))
{
a/=n;
res*=n;
}
else if((a%n!=0)&&(b%n==0))
{
b/=n;
res*=n;
}
else if((a%n!=0)&&(b%n!=0))
{
n++;
}
}
printf("\n LCM of a and b is %d",res);
}
Is This Answer Correct ? | 0 Yes | 2 No |
Answer / khadanga
public class LCM {
public static void main(String a[]){
test(0,9);
}
static void test(int a,int b){
if(a==0 || b==0){
return;
}
int n;
int increment;
if(a>b){
n = a;
increment = a;
}else{
n = b;
increment = b;
}
while(true){
if(n%a == 0 && n%b == 0){
break;
}else if(n > (a*b)){
n = a*b;
break;
}else{
n = n+increment;
}
}
System.out.println("LCM for "+a+" and "+b+" is "+n);
}
}
Is This Answer Correct ? | 3 Yes | 6 No |
Answer / shailendra
#include <iostream>
using namespace std;
int main()
{
int x,y,z;
cout<<"Enter First Integer:";
cin>>x;
cout<<"\nEnter Second Integer:";
cin>>y;
z=1;
while(x/z==1 && y/z==1)
{
z=x/y;
cout<<"The LCM of Both Numbers is:"<<z;
}
return 0;
}
Is This Answer Correct ? | 8 Yes | 69 No |
Diff.b/w Frames and container?
1 Answers Tech Mahindra, Wipro,
Differevce between arrays and array builders?
What is the difference between procedure -oriented language and object oriented language?
22 Answers IBM, Infosys, TCS,
How to swap values between two variables without using a third variable?
24 Answers HCL, TCS,
How many packages available in java??
How to display questions one by one in jsp and I wants to store the answers in my database?
can php support multiple inheritence?
two MIT math grads bump into each other at Fairway on the upper west side. they haven't seen each other in over 20 years. the first grad says to the second: "how have you been?" second: "great! i got married and i have three daughters now" first: "really? how old are they?" second: "well, the product of their ages is 72, and the sum of their ages is the same as the number on that building over there.." first: "right, ok.. oh wait.. hmm, i still don't know" second: "oh sorry, the oldest one just started to play the piano" first: "wonderful! my oldest is the same age!" problem: how old are the daughters?
There are 2 tables: EMP : EmpId, Ename, Sal, DeptId DEPT : DeptId, Dname Write a query to find out emp names and their department names. if any emp has null in Deptid the it shows ?No Department?. Write a query to find out those department names which has no employee. Write a query to find out those employees whose salary is greater than their department?s average salary.
Find out the list of roles which gives access to GUI activities? thanks in advance
where is available in this mantis toturials?
qtp 9.2 14 days demo version was expired.I uninstalled how to reinstall this again