伊思洗面奶价格查询:c语言,编译通过,运行显示Floating point error:Divide by 0.

来源:百度文库 编辑:中科新闻网 时间:2024/05/03 11:35:55
#include <math.h>
#include <stdio.h>
main()
{ int t=1,k=1;
float sum=1,s;
do{ t=t*k;
s=1.0/t;
sum=sum+s;
k++;
}
while(fabs(s)>=1e-5);
printf("%f\n",sum);
}

编译通过,运行错误,alt+f5显示
Floating point error:Divide by 0.
为什么,错在哪里??

应该没有问题,实在不行你在s=1.0/t;语句前加一个判断t是否不等于0,按你的程序应该不会出现等于零的情况,不行的话就把s,sum类型设为double