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 |
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.
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
how to convert hashmap to arraylist with iteration
How to call dll API sub routine in VB Form.
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.
how we can connect applet with database?
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.
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
I am looking for NIC Sample papers or any patern of questions/ syllabus plz, send me on hamid.khan135@yahoo.in Regard
what do you meant by Platform-Independent in Java?
what is dot net framework
I want Ada programming language books. Could anyone post me any link for that?