C语言Matrix编程题——[Recursion]D. Liang 8.3 Computing greatest common divisor using recursion

[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小白修炼手册

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值