最大公约数问题?求助!!!
#include<iostream>#include<cmath>
using namespace std;
int main()
{
int x,y;
cout<<"please enter two integer numbers:";
cin>>x>>y;
x=(x+y+fabs(x-y))/2;
y=(x+y-fabs(x-y))/2;
int r;
do
{
r=x%y;
x=y;
y=r;
}
while(r);
cout<<"The common denominator is: "<<x<<endl;
return 0;
}
运行结果:
7和8的最大公约数不是1吗?怎么是8,是我写的程序有错吗?还望高手指教,谢谢!