Recursive program to calculate Greatest Common Divisor Of 2 programs.

Recursive program to calculate Greatest Common Divisor Of 2 programs.
class GCD{
public void accept(int n1,int n2){
int big=(n1>n2)?n1:n2;
int small=(n1<n2)?n1:n2;
int gcd=Grcodi(big,small);
System.out.print("The greatest common divisor"+"\t\t"+gcd);
}
int Grcodi(int p,int q){
if(q==0)
return p;
return Grcodi(q,p%q);
}//accept
}//End of class
OUTPUT---
When Input is 3 & 2
The greatest common divisor 1

Comments

Popular posts from this blog

Sort Boundary Elements Of A Matrix

Lucky Number In Java ISC

Program to fill a square matrix of size ‘n*n” in a circular fashion (clockwise) with natural numbers from 1 to n*n, taking ‘n’ as input.