gcd-函数

时间:2014-10-06 21:14:30   收藏:0   阅读:430

在网上看到了这个函数

int gcd(int a,int b)
{
if(a==0) return b;
if(b==0) return a;
return gcd(b,a%b);
}

是求最大公约数的 有了这个函数之后,求最大公约数就好很多了

不过可以这样写

int gcd(int a,int b)
{
//if(a==0) return b;
if(b==0) return a;
return gcd(b,a%b);
}

 

a==0 这行可以不要

原文:http://www.cnblogs.com/liudehao/p/4008682.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!