Gcm And Lcm Of Two Numbers

in Hindi - Gcm And Lcm Of Two Numbers



not yet

Source Code :

RUNimport java.util.Scanner;

public class LCMGCD
{
public static void main(String args[])
{

int num1,num2,temp1,temp2,gcd=0,lcm;

System.out.print("Enter two numeric values : ");
Scanner enter = new Scanner(System.in);
num1 = enter.nextInt();
num2 = enter.nextInt();

temp1=num1;
temp2=num2;

if(temp1 == 0)
{
gcd=temp2;
}
else if(temp2 == 0)
{
gcd=temp1;
}
else
{
while(temp2 != 0)
{
if(temp1 > temp2)
{
temp1=temp1-temp2;
}
else
{
temp2=temp2-temp1;
}
gcd=temp1;
}
}
lcm = (num1*num2) / gcd ;
System.out.println("LCM of " + num1 + " and " + num2 + " is " + lcm);
System.out.println("GCD of " + num1 + " and " + num2 + " is " + gcd);

}
}