Program in Java: To accept two numbers. Display the HCF/GCD/GCF and LCM of the numbers using While Loop
Program in Java: To accept two numbers. Display the HCF/GCD/GCF and LCM of the numbers using While Loop
/**
* Program in Java: To accept two numbers. Display the HCF/GCD/GCF and LCM of the numbers using While Loop.
*/
import java.util.Scanner;
class prg3
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter two numbers:");
int a = sc.nextInt();
int b = sc.nextInt();
int c=a,d=b;
while(d!=0)
{
int k=d;
d=c%d;
c=k;
}
int hcf=c;
int lcm=(a*b)/hcf;
System.out.println("HCF of two numbers:"+hcf);
System.out.println("LCM of two numbers:"+lcm);
}
}