现在的位置: 首页 > 综合 > 正文

算法之 求两个数的最大公约数 C++实现

2014年10月18日 ⁄ 综合 ⁄ 共 178字 ⁄ 字号 评论关闭
////欧几里得算法(求两个数的最大公约数)
int God(int M,int N)
{
int rem ;
while(N > 0)
{
rem=M%N;
M=N;
N=rem;
}
return M;
}

 

调用:

 

int _tmain(int argc, _TCHAR* argv[])
{
    int rlt = God(360,60);
    cout<<rlt<<endl;
cin.get();
    return 0;
}

抱歉!评论已关闭.