Java program to find GCD using recursion


Program
import java.util.*; public class GcdRecursion { public static void main(String[] args) { Scanner s=new Scanner(System.in); System.out.println("Enter the any two number to find GCD using recursion"); int a=s.nextInt(); int b=s.nextInt(); int g = gcd(a,b); System.out.format("G.C.D of %d and %d is %d.", a, b, g); } public static int gcd(int a, int b) { if (b != 0) return gcd(b, a % b); else return a; } }
Input
Output