40) Write a program to input two integers
and find the HCF of two numbers?
(10,12. HCF=2)
import java.util.*;public class HCF{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();for(int i = Math.min(a,b);i>=1;i--){if(a%i==0&&b%i==0){System.out.println("H.C.F of "+a+" and "+b+" = "+i);break;}}}}
No comments:
Post a Comment
if you have any doubts, Please let me know.
Your Truly
Shashank Porwal