public class EuclidGCdAlgorithmn {
public static int gcd(int p, int q) {
if (q == 0) {
return p;
}
return gcd(q, p % q);
}
// Test enable assert check via -ea as a VM argument
public static void main(String[] args) {
System.out.print(" "+gcd(4, 16));
System.out.print(" "+gcd(16, 4));
System.out.print(" "+gcd(15, 60));
System.out.print(" "+gcd(15, 65));
System.out.print(" "+gcd(1052, 52));
}
}
Below is the output....
4
4
15
5
4
No comments:
Post a Comment