Kotlin Program to Find G.C.D Using Recursion: In this program, you’ll learn to find GCD of two numbers in Kotlin. … The HCF or GCD of two integers is the largest integer that can exactly divide both numbers (without a remainder).
Kotlin Program to Find G.C.D Using Recursion
Source Code
fun main(args: Array<String>) {
val n1 = 366
val n2 = 60
val hcf = hcf(n1, n2)
println("G.C.D of $n1 and $n2 is $hcf.")
}
fun hcf(n1: Int, n2: Int): Int {
if (n2 != 0)
return hcf(n2, n1 % n2)
else
return n1
}
Output