This document contains code to calculate the greatest common divisor (GCD) of two integers using recursion. It takes two numbers as input, calls a recursive HCF function that calculates the GCD by repeatedly dividing the larger number by the remainder of dividing it by the smaller number until the remainder is 0, at which point the smaller number is the GCD, and prints out the GCD of the two input numbers.
This document contains code to calculate the greatest common divisor (GCD) of two integers using recursion. It takes two numbers as input, calls a recursive HCF function that calculates the GCD by repeatedly dividing the larger number by the remainder of dividing it by the smaller number until the remainder is 0, at which point the smaller number is the GCD, and prints out the GCD of the two input numbers.
This document contains code to calculate the greatest common divisor (GCD) of two integers using recursion. It takes two numbers as input, calls a recursive HCF function that calculates the GCD by repeatedly dividing the larger number by the remainder of dividing it by the smaller number until the remainder is 0, at which point the smaller number is the GCD, and prints out the GCD of the two input numbers.
System.out.printf("THE G.C.D of %d and %d is %d.", n1, n2, hcf); || Final
H.C.F(6,0) (6, 0, -) }
public static int hcf(int n1, int n2) || n2 is
0.in the end the value of n1 is G.D.C or H.C.F of the given two numbers { if (n2 != 0) return hcf(n2, n1 % n2); || No. Recursive call n1 n2 n1%n2 else return n1; } }