PLease see once what is the error in my code
GCD of two no.s
Hey @ananyakulshrestha21
for (int i = 1; i <= n1 && i <= n2; i++) {
if (n1 % i == 0 && n2 % i == 0) {
gcd = i;
System.out.println(gcd);
}
}
//These things are wrong
Let us consider some of the examples to find highest common factor (H.C.F) by using division method.
public static int gcd(int dividend, int divisor){
while(dividend % divisor != 0){
int rem = dividend % divisor;
dividend = divisor;
divisor = rem;
}
return divisor;
}
dry run this logic