你赶上好运了,哈哈,我刚也做这个题,刚做好!求采纳哦
#include
#include
#define max 100
typedef struct
{
int a[max];
int top;
} sqstack;
void initstack (sqstack *&s)
{
s=(sqstack *)malloc(sizeof(sqstack));
s->top=-1;
}
bool push(sqstack *&s,int e)
{
if(s->top==max-1)
return false;
s->top++;
s->a[s->top]=e;
return true;
}
bool pop(sqstack *&s,int &e)
{
if(s->top== -1)
return false;
e=s->a[s->top];
s->top--;
return true;
}
bool stackemply(sqstack *s)
{
return(s->top==-1);
}
int main()
{
int n,m,e;
sqstack *s;
initstack (s);
printf("输入一个数:");
scanf("%d",&n);
while(n)
{
m=n%2;
push(s,m);
n=n/2;
}
printf("转化二进为:");
while(!stackemply(s))
{
pop(s,e);
printf("%d",e);
}
return 0;
}