Write a Pseudo Code to fins the LCM of two given numbers

Answers were Sorted based on User's Feedback



Write a Pseudo Code to fins the LCM of two given numbers..

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

Write a Pseudo Code to fins the LCM of two given numbers..

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

Write a Pseudo Code to fins the LCM of two given numbers..

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

Write a Pseudo Code to fins the LCM of two given numbers..

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

Write a Pseudo Code to fins the LCM of two given numbers..

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

Post New Answer

More Programming Languages AllOther Interview Questions

I've an application where i need to give access to all the features only to admin and only few features to normal users. Say Menu...i dont want all my menu items to be accessible to all the users only the admin people can see few all the features where as normal users can have access to limited menu items...how can i achieve this. Please note that my menu is not a database driven menu.

1 Answers   Tesco,


hi this is uday i want prepare for nic exam if any one have previous question papers please send me or atlest guide me how to prepare my ID is udaykiran4u@in.com

0 Answers  


how to convert hashmap to arraylist with iteration

0 Answers   DFD,


How to call dll API sub routine in VB Form.

0 Answers  


19. Given a system that is described with the following equation, X=A+(B.(A̅+C)+C)+A.B.(D̅+E̅) a) Simplify the equation using Boolean Algebra. b) Implement the original and then the simplified equation with a digital circuit. c) Implement the original and then the simplified equation in ladder logic.

0 Answers   Bajak Paint,






how we can connect applet with database?

1 Answers  


write a query that returns one row for each department and the number of employees in that department. Given two tables EMPLOYEE and DEPARTMENT, where there can be multiple employees per department.

0 Answers   IBM,


hai i am mca 2009 fresher.please tell me which certification helps me to get an IT job faster which institute is good in hyderabad.please mail me to prasanna.1856@rediff.com

0 Answers  


I am looking for NIC Sample papers or any patern of questions/ syllabus plz, send me on hamid.khan135@yahoo.in Regard

0 Answers   NIC,


what do you meant by Platform-Independent in Java?

6 Answers   Persistent,


what is dot net framework

0 Answers   NIC,


I want Ada programming language books. Could anyone post me any link for that?

0 Answers  


Categories