#define maxnum 20
#include<stdio.h>
#include<stdlib.h>
struct stacktype
{
int stack[maxnum];
int top;
};
int push(struct stacktype *s,int x)
{
if(s->top>=maxnum-1)
return false;
else
s->top++;
s->stack[s->top]=x;
return true;
}
int pop(struct stacktype *s)
{
if(s->top <0)
return NULL;
else
s->top--;
return(s->stack[s->top+1]);
}
dec_to_bin(int n,int b)
{
int e;
InitStack(S);//请问初始化堆栈函数怎么写?
while(n)
{
push(S,n%b);
n=n/b;
}
while(!StackEmpty)//判断栈为空的函数怎么写?
{
e=pop(S);
printf("%d",e);
}
}
main
{
dec_to_bin(13,2);
}