Program to calculate the GCD of two number using recusion
import java.util.*;
public class GDC{
public static int gcd(int a, int b){
if(b==0)
return a;
return gcd(b,a%b);
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the n1: ");
int n1 = sc.nextInt();
System.out.println("Enter the n2");
int n2 = sc.nextInt();
System.out.println(gcd(n1,n2));
}
}
No comments:
Post a Comment
If you have any doubt . Please let me know