Computer Science, asked by kaiva26, 1 year ago

write a program to find the LCM & GCD of two numbers


LuckyYadav2578: in which language?
kaiva26: computer
kaiva26: english
LuckyYadav2578: computer but ... html , python,c++,c
LuckyYadav2578: etc
kaiva26: java
LuckyYadav2578: ohk ... sorry

Answers

Answered by rishabh20004
4
import java.util.Scanner; public class JavaProgram { public static void main(String args[]) { int a, b, x, y, t, hcf, lcm; Scanner scan = new Scanner(System.in); System.out.print("Enter Two Number : "); x = scan.nextInt(); y = scan.nextInt(); a = x; b = y; while(b != 0) { t = b; b = a%b; a = t; } hcf = a; lcm = (x*y)/hcf; System.out.print("HCF = " +hcf); System.out.print("\nLCM = " +lcm); } }
Similar questions