[Recursion]D. Liang 8.3 Computing greatest common divisor using recursion
Description:
用以下的函数完成一个计算最大公约数的函数
int gcd(int n, int m)
Input:
两个正整数n,m(n<=100000,m<=100000),用空格或回车隔开
Output:
输出n和m的最大公约数
Sample Input:
16 24
Sample Output:
8
Hint:
Don’t submit the main() function.
Programme:
//Date:2020/6/3
//Author:Kamenrider Justice
int gcd(int n, int m)
{
int temp;
if(n<m)//大的数放在n中
{
temp=n;
n=m;
m=temp;
}
if(n%m==0)
{
return m;
}
else
{
return gcd(m,n%m);
}
}
Java小白修炼手册