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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

write the a cl program with the following specification A. Accept 2 parameters-date and date type B. if date type is J then convert date to *MDY format C. if date type is M convert date to *JUL format 4.send a program message with the value of converted date Please explain for each with coding?

2189


Colors specified with the notation

1815


why we use abstract word in abstract window toolkit in java language.

1770


how can i create report in abap to insert data in table pa0002 using insert command

1718


Write a program to find factorial of a number using functions

1261






1. Write a program to create a sentence at runtime and count number of vowels in it ? 2. Write a program to get a string and to convert the 1st letter of it to uppercase ?

3216


Is anyone has done the ASP.NET MVC4 workshop course(2 days) from Peers Technologies. Let me know. I need to talk before joining ASP.NET MVC4 training at peers, Hyderabad.

1556


4. What is the need of START 0? Instead if can we use any other numeric? If we use what will happen?

1903


HOW TO FIND NUMBER OF TWOS IN N!(N FACTORIAL)??

1789


what is the work of 1tier,2tier,&ntier? Plz Explain it!

2043


5.Call by value and Call by reference with program?

1838


What do you understand by modular programming?

674


Definition of Singleton Class? what is the Purpose of it? what is the advantage?

1595


what is programmable BIST in today ic design

1651


Given a Binary Search Tree, write a program to print the kth smallest element without using any static/global variable. You can?t pass the value k to any function also.

562