#include
//转化为2进制
void z2(int n)
{
if (n > 1)
{
z2(n / 2);
}
printf("%d", n%2);
}
void z21(long double f,int c)
{
float twice;
int tmp;
if (c == 0)
return ;
twice = f * 2;
tmp = (int)twice;
printf("%d", tmp);
z21(twice - tmp, --c);
}
void z211(int zhengshu, float xiaoshu)
{
// 输出整数部分
z2(zhengshu);
if (xiaoshu > 0.000001)
{
printf(".");
}
// 输出小数部分
z21(xiaoshu, 10);
}
void z8(int n)
{
if(n>7)
{
z8(n/8);
}
printf("%d",n%8);
}
void z81(long double f,int c)
{
double twice;
int tmp;
if(c==0)
return ;
twice=f*8;
tmp=(int)twice;
printf("%d",tmp);
z81(twice-tmp,--c);
}
void z811(int zhengshu,float xiaoshu)
{
z8(zhengshu);
if(xiaoshu>0.000001)
{
printf(".");
}
z81(xiaoshu,10);
}
char c1[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
void z16(int n)
{
if(n>15)
{
z16(n/16);
}
printf("%c",c1[n%16]);
}
void z161(long double f,int c)
{
long double twice;
int tmp;
if(c==0)
return ;
twice=f*16;
tmp=(int)twice;
printf("%c",c1[tmp]);
z161(twice-tmp,--c);
}
void z1611(int zhengshu,float xiaoshu)
{
z16(zhengshu);
if(xiaoshu>0.000001)
{
printf(".");
}
z161(xiaoshu,10);
}
void main()
{
float shu = 0;
int zhengshu = 0;
printf("请输入一个十进制数:");
scanf("%f", &shu);
if(shu < 0)
{
printf("-");
shu *= -1;
}
zhengshu = (int)shu;
shu -= zhengshu;
z211(zhengshu,shu);
printf("\n");
z811(zhengshu,shu);
printf("\n");
z1611(zhengshu,shu);
printf("\n");
}
这个程序输出的是第一张图,怎么改正成为第二张图啊,着急!