Guest User

Untitled

a guest
Jul 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. //GCD/HCF of two numbers
  2. public class gcd_of_two_numbers {
  3.  
  4. public static void main(String[] args) {
  5. int n1 =12, n2= 99, gcd=1;
  6.  
  7. for(int i = 1; i<=n1 && i<=n2; ++i) {
  8. // check if i is factor of these both numbers
  9. if(n1%i==0 && n2 %i==0) {
  10. gcd = i;
  11. }
  12. }
  13. System.out.println("gcd of "+n1+" and "+n2+" is : "+gcd);
  14.  
  15. }
  16.  
  17. }
Add Comment
Please, Sign In to add comment