Aim: To Find LCM of two numbers using loop
Syntax:
/* LCM using loop
*
* by Aditya Sureka
*/
//import the IO package
import java.io.*;
public class program15 //class name
{
public static void main(String args[])throws IOException ///main function
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the two nos.");
//Accept the inputs from the user
int big=Integer.parseInt(br.readLine());
int small=Integer.parseInt(br.readLine());
int rem=1;//Intialize Remainder =1
while(rem!=0)//while remainder is not equal to 0
{
rem=big%small; //FInd the remainder
if(rem!=0)//If the remainder is not equal to 0,proceed
{
big=small;
small=rem;
}
}
// Print the LCM
System.out.println(small);
}
}
Syntax:
/* LCM using loop
*
* by Aditya Sureka
*/
//import the IO package
import java.io.*;
public class program15 //class name
{
public static void main(String args[])throws IOException ///main function
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the two nos.");
//Accept the inputs from the user
int big=Integer.parseInt(br.readLine());
int small=Integer.parseInt(br.readLine());
int rem=1;//Intialize Remainder =1
while(rem!=0)//while remainder is not equal to 0
{
rem=big%small; //FInd the remainder
if(rem!=0)//If the remainder is not equal to 0,proceed
{
big=small;
small=rem;
}
}
// Print the LCM
System.out.println(small);
}
}
No comments:
Post a Comment