#include<stdio.h>
int fun(int m,int n)
{
int r;
if(n > m)
{
return fun(n,m);
}
else
if(n == 0)
{
return m;
}
else
{
r = m % n;
return fun(n,r);
}
}
/*运用非递归的思想计算,速度会被加快*/
int fun2(int m, int n)
{
int r;
do
{
r = m % n;
m = n;
n = r;
}while(r != 0);
return m;
}
int main()
{
int m,n;
int re,re2;
printf("请输入两个数求出它们的最大公约数(以逗号隔开)!\n");
scanf("%d,%d",&m,&n);
re = fun(m,n);
printf("递归re = %d\n",re);
fun2(m,n);
re2 = fun(m,n);
printf("非递归re2 = %d\n",re2);
return 0;
}