41) Write a program to input two integers
and find the GCD/HCF of two numbers
(using division method)? (10,12, HCF=2)
import java.util.*;public class GCD{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 k = Math.min(a,b);b = Math.max(a,b);a=k;while(k!=0){k=b%k;if(k!= 0){b=a;a=k;}}System.out.println("G.C.D = "+a);}}
GCD-of-two-numbers 40) Write a program to input two integers
and find the HCF of two numbers?
(10,12. HCF=2) |