发现个错误... 修改了下..
#include
#include
void outint(int);
void outfloat(float ,int );
int main()
{
float num; //需要转换的数
int i,count; //i为用来存放num的整数部分 count是输出结果保留的小数位数
float f;//f用来存放num的小数部分
printf("Please enter a decimal count:");
scanf("%f",&num);
if(num>10240.0||num
{
printf(" You must use a high-level calculator,I can't help you!!!!\n");
exit(1);
}
i=num;
f=num-i;
printf("How many decimal do you want to retain:");
scanf("%d",&count);
printf("The count entered by you has been changed,look!!!--> ");
outint(i);
outfloat(f,count);
printf("B\n");
}
void outint(int i)
{
int a[32],m=0,n=0,mod;
int next=0;
if(i==0)
{
printf("0");
exit(0);
}
if(i>=0)
{
while(i/2>=1)
{
a[next]=i%2;
++next;
i/=2;
}
a[next]=1;
next++;
a[next]=0;
}
else
{
i*=-1;
while(i/2>=1)
{
a[next]=i%2;
++next;
i/=2;
}
a[next]=1;
next++;
a[next]=1;
}
for(m=0;m<=next-m;m++)
{
mod=a[m];
a[m]=a[next-m];
a[next-m]=mod;
}
for(m=0;m<=next;m++)
printf("%d",a[m]);
}
void outfloat(float f,int count)
{
int a[32],next=0,i;
printf(".");
if(f==0.0)
{
printf("0");
goto out;
}
if(f<0)
f*=-1;
while(f*2.0!=1.0)
{
if(f*2.0>1.0)
{
a[next]=1;
next++;
f=f*2.0-1.0;
}
else
{
a[next]=0;
next++;
f=f*2.0;
}
}
for(i=0;i
printf("%d",a[i]);
out:
;
}