代码如下:
#include <stdio.h>
#include <malloc.h>#define MAXSIZE 100
typedef struct{/*栈的定义*/
int data[MAXSIZE];
int top;
}Seqstack;
Seqstack *Initstack(){/*栈的初始化*/
Seqstack *s;
s=(Seqstack *)malloc(sizeof(Seqstack));
s->top=-1;
return s;
};
Seqstack* Pushstack(Seqstack *s,int x){/*进栈函数*/
if(s->top==MAXSIZE-1)
printf("ERROR");
else{
s->top++;
s->data[s->top]=x;
return s;
}
};
void Popstack(Seqstack *s,int x){/*出栈函数*/
if(s->top==-1)
printf("ERROR");
else{
x=s->data[s->top];
s->top--;
printf("%d",x);
}
}
int main(){
int n,m,x;
scanf("%d%d",&n,&m);
Seqstack *s;
s=Initstack();
while(n){/*进制转换*/
Pushstack(s,n%m);
n=n/m;
}
while(s->top!=-1){
Popstack(s,x);
}
return 0;
}