这个算法适用于检查终止小数吗?

Loe*_*rio 0 decimal

int is_ter(int x)
{
    //it is not a TWOs nor a FIVEs and not 1.0
g:  
    if(x%2 !=0 && x%5 !=0 && x!=1 )
        return 0;
    // make sure it is 1.0
    if(x%2 !=0 && x%5 !=0 && x==1 )
        return 1;
    //check if it is a two
    if(x%2==0){
         x/=2;
         goto g;
    }
    if(x%5==0)
    {
        x/=5;
        goto g;
    }
}
Run Code Online (Sandbox Code Playgroud)

Chr*_*ber 5

从它的外观来看,你想检查1/x是否正在终止.

你的代码看起来有点令人困惑.你需要检查你的所有主要因素是2还是5:

int is_ter(unsigned int x)
{
    while (x>1)
    {
       if (x%2==0) x=x/2;
       else if (x%5==0) x=x/5;
       else return 0;
    }
    return 1;
}
Run Code Online (Sandbox Code Playgroud)

应该做的伎俩(好吧,它说1/0正在终止,无论这意味着什么.它将终止程序,所以它并非完全错误......)