注册 登录
编程论坛 新人交流区

找问题啊

baiyy0906 发布于 2007-11-10 22:48, 278 次点击

这是一道小数把十进制转二进制的题 运行有问题 大家帮我看看有什么问题


#include<stdio.h>
#include<stdlib.h>
#define MAXLEN 100
typedef struct
{
int q[MAXLEN];
int front;
int rear;
}sqtype;

void initqueue(sqtype *sq)
{
sq->front=-1;
sq->rear=-1;
}

int empty(sqtype *sq)
{
if(sq->front==sq->rear)return 1;
return 0;
}

int full(sqtype *sq)
{
if(sq->front==(sq->rear+1)%MAXLEN)return 1;
return 0;
}
void addqueue(sqtype *sq,int x)
{
if(full(sq)==1)
{
printf("full");
return;
}
sq->rear=(sq->rear+1)%MAXLEN;
sq->q[sq->rear]=x;
}

int delqueue(sqtype *sq)
{
int x;
if(empty(sq)==1)
{
printf("empty");
return 0;
}
sq->front=(sq->front+1)%MAXLEN;

x=sq->q[sq->front];
return x;
}

void main()
{
sqtype *sq;
sq=(sqtype *)malloc(sizeof(sqtype));
float x=;
int y=0,n=0;
scanf("%d",&x);
initqueue(sq);
while(x!=0)
{
x=x*2;
if(x>=1)
{
y=1;
x=x-1;
}
else y=0;
addqueue(sq,y);

}
while(empty(sq)!=1)
{
n=delqueue(sq);
printf("%f",n);
}
printf("\n");
}

2 回复
#2
nuciewth2007-11-10 22:51
太长了啦.
我的建议就是划成整数再弄,要不就截段转换.
#3
aohing2007-11-11 18:32
在主函数里那个float x=;
是不是有问题
1