//辗转相除法求最大公约数
static int TestMath(int a,int b)
{
int r = 0;//保存最大公约数
//排序,a保存较大数,b保存较小数
if (a < b)
{
int temp=a;
a=b; b= temp ;
}
//求最大公约数
while (a % b != 0)
{
int temp = b;
b = a % b;
a = temp;
}
r = b;
return r;
}
转载于:https://www.cnblogs.com/dongweian/p/7944706.html