Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //GCD/HCF of two numbers
- public class gcd_of_two_numbers {
- public static void main(String[] args) {
- int n1 =12, n2= 99, gcd=1;
- for(int i = 1; i<=n1 && i<=n2; ++i) {
- // check if i is factor of these both numbers
- if(n1%i==0 && n2 %i==0) {
- gcd = i;
- }
- }
- System.out.println("gcd of "+n1+" and "+n2+" is : "+gcd);
- }
- }
Add Comment
Please, Sign In to add comment