问题?非法指令?(辗转相除法带来的问题)(已解决)

#include

int main() { //有限小数点位数 int weishu = 1; double double1; scanf("%lf",&double1); double substitute_double1 = double1;

double double10;
do
{
    double10 = double1*10;
    double1 = double10 - (int)double10;
    weishu++;
} while ((int)double1 != 0);
//printf("%d\n",weishu);

//得到最大公约数(辗转相除法)
int fm = pow(10,weishu);
int fz = substitute_double1*fm;
int substitute_fm = fm;
int substitute_fz = fz;
int yushu;
while (substitute_fz !=0) {
    yushu = substitute_fm%substitute_fz;
    substitute_fm = substitute_fz;
    substitute_fz = yushu;
}
//最大公约数为substitute_fz
int simple_fm = fm/substitute_fz;//得到最简分子,分母
int simple_fz = fz/substitute_fz;

问题及上,除以fz = 0,故报错。
应除以fm,为:
int simple_fm = fm/substitute_fm;//得到最简分子,分母
int simple_fz = fz/substitute_fm;


//printf("%d\n",substitute_fz);
//输出有限分式结构
printf("%f的分式结构%d\/%d",substitute_double1,simple_fz,simple_fm);

return 0;

}

JSRUN前端笔记, 是针对前端工程师开放的一个笔记分享平台,是前端工程师记录重点、分享经验的一个笔记本。JSRUN前端采用的 MarkDown 语法 (极客专用语法), 这里属于IT工程师。