class ex1
{
int gys1(int m, int n) // 循环实现
{
int k,y;
if(m{
k=m;
m=n;
n=k;
}
while(m%n!=0)
{
y=m%n;
m=n;
n=y;
}
return n;
}
int gys2(int m,int n) //递归实现
{
int k,y;
if(m{
k=m;
m=n;
n=k;
}
y=m%n;
if(y==0)
{
return n;
}
else
{
m=n;
n=y;
return gys2(m,n);
}
}
public static void main(String[] args)
{
ex1 e1=new ex1();
System.out.println(e1.gys1(12,8));
ex1 e2=new ex1();
System.out.println(e1.gys2(12,8));
}
}
就是用java写呗。。。辗转相除法就是了