浮点数错误
#include <stdio.h>#include <stdlib.h>
#include<math.h>
int main()
{ int a,b,c,d,e;
printf("Please enter the number:\n");
scanf("%d",&a);
for(b=1,d=0;c!=0;++d)
{ a=(int)fabs(a);
c=a/b;
b=b*10;
}
printf("%d: %d bits\n",a,d-1);
int f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o,p,q=0,r;
p=1;
e=b/100;
o=a;
do { r=o%e;
o=o/e;
e=e/10;
switch(o){
case 0:
f++;
break;
case 1:
g++;
break;
case 2:
h++;
break;
case 3:
i++;
break;
case 4:
j++;
break;
case 5:
k++;
break;
case 6:
l++;
break;
case 7:
m++;
break;
case 8:
n++;
break;
case 9:
q++;
break;
}
if(e==0)
{
p=0;
}
o=r;
}while(p!=0);
if(f!=0)
{
printf("0: %d\n",f);
}
if(g!=0)
{
printf("1: %d\n",g);
}
if(h!=0)
{
printf("2: %d\n",h);
}
if(i!=0)
{
printf("3: %d\n",i);
}
if(j!=0)
{
printf("4: %d\n",j);
}
if(k!=0)
{
printf("5: %d\n",k);
}
if(l!=0)
{
printf("6: %d\n",l);
}
if(m!=0)
{
printf("7: %d\n",m);
}
if(n!=0)
{
printf("8: %d\n",n);
}
if(q!=0)
{
printf("9: %d\n",q);
}
return 0;
}
这个程序在中国大学运行的时候提示浮点数错误,但输出结果没问题,单步测试中也没有发现变成了浮点数,谢谢大佬指正。