普通网友 2016-12-04 03:07 采纳率: 0%
浏览 844

求助C语言大神,我的这个程序错在哪了,如何改正!!

#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");
}

图片说明

这个程序输出的是第一张图,怎么改正成为第二张图啊,着急!

  • 写回答

4条回答 默认 最新

  • 普通网友 2016-12-04 03:12
    关注

    图片说明

    图错了,这是正确的图

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题