Output:
Click Here For Java Online Compiler
Solution:
*** HCF Of Two Numbers *** Enter the first number: 3 Enter the second number: 4HCF: 1
Click Here For Java Online Compiler
Solution:
import java.util.Scanner; class HCF { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int dividend, divisor; int remainder, hcf = 0; System.out.println("*** HCF Of Two Numbers ***" + "\n"); System.out.print("Enter the first number: "); dividend = scanner.nextInt(); System.out.print("Enter the second number: "); divisor = scanner.nextInt(); do { remainder = dividend % divisor; if(remainder == 0) { hcf = divisor; } else { dividend = divisor; divisor = remainder; } } while (remainder != 0); System.out.println("HCF: " + hcf); } }
comment 1 comments:
more_vertNice article for find hcf for two number . you can visit one more way to find HCF and LCM of two number
11 April 2020 at 02:58sentiment_satisfied Emoticon