public class CWH_PS5 {import java.util.Scanner;
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

0 Comments