#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int main()
{
double a,b,res;
while(cin>>a>>b)
{
res = a/b;
if((res*b) == a)
cout<<"Terminates"<<endl;
else
cout<<"Does not terminate"<<endl;
}
return 0;
}
所以,这里是我的代码,看看如果a/b导致终止小数或不。一些输入产生正确的输出,如:终止十进制
1/3:不终止,
1/9:不终止,
1/7:不终止,
22/7:不终止,
1/2:终止。
除1/5应显示:1/5 : Terminates
,但输出为:Does not terminates
。
我知道C++浮点存在很多问题,试图谷歌,但它就像一个谜题。
在二进制算术中,1/5是非终止分数。 –
你能解释更多请@PatriciaShanahan – inhaler
好的,我有种得到它@PatriciaShanahan – inhaler