//Write a program to find GCD or HCF of two numbers


import
java.util.Scanner;
public class CWH_PS5 {
public static void main(String[] args) {

int i,a,b, hcf = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first no");
a = sc.nextInt();
System.out.println("Enter the second no");
b = sc.nextInt();
for(i=1; i<=a || i<=b; i++){
if( a%i ==0 && b%i==0)
hcf = i
;
}
System.
out.println("hcf of given no is : "+hcf);
}
}

//output
Enter the first no 2 Enter the second no 4 hcf of given no is : 2 Process finished with exit code 0



 

Post a Comment

0 Comments