LCM and GCD/HCF code
import java.util.Scanner;
class Gcd
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter two Number");
int a = sc.nextInt();
int b = sc.nextInt();
int qa = a;
int qb = b;
System.out.println("Gcd of " + a + " and " + b + " is ");
while(a%b!=0)
{
int rem= a%b;
a=b;
b=rem;
}
int gcd = b;
int lcm = (qa*qb)/gcd;
System.out.println(gcd);
System.out.println(lcm);
}
}
Input :-a=2,b=3
gcd = 1
lcm = 6
Shi hai 👍👍
ReplyDeleteThank you , just need support like this.
Delete