C++ 计算最大的普通分频器的计划
我推出了这个程序来计算最大的公共分频器。 这是我到目前为止的目标:
我总是得到 0 为了 GCD. 我究竟做错了什么?
</math.h></iostream>
#include <iostream>
#include <math.h>
using namespace std;
int getGCD/int a, int b/
{
a = a % b;
if /a == 0/
{
return b;
b = b % a;
}
if /b == 0/
{
return a;
}
}
int main//
{
int x, y;
cout << "Please enter two integers x and y, for GCD calculation" << endl;
cin >> x >> y;
cout << "The GCD of " << x << "and " << y << " is" << getGCD/x, y/ << endl;
return 0;
}
我总是得到 0 为了 GCD. 我究竟做错了什么?
</math.h></iostream>
没有找到相关结果
已邀请:
2 个回复
莫问
赞同来自:
//here 我们需要检查是否回报是否 b == 0 a
欧几里德算法的实施
知食
赞同来自:
但我看到你有两个问题,除非你在另一个周期内称之为。
你在这两种情况下返回,或者如果,或其他,所以你只去这里一次。
此外,这部分没有意义,为什么改变价值
执行后
?
顺便说一下,为此,您应该使用递归。
http://rosettacode.org/wiki/Gr ... rithm