#define Stack_Size 50/*数制转换*/ #define FALSE 0 /*2009.08.17*/ #define TRUE 1 typedef int StackElemType; typedef struct { StackElemType elem[Stack_Size];//用数组模拟栈 int top; }SeqStack; void InitStack(SeqStack *s)//初始化 { s->top=-1; } int Push(SeqStack *s,StackElemType x)//入栈操作 { if(s->top==Stack_Size-1) return FALSE; s->top++; s->elem[s->top]=x; return TRUE; } int IsEmpty(SeqStack *s)//判断是否为空 { if(s->top==-1) return TRUE; else return FALSE; } int Pop(SeqStack *s,StackElemType *x)//出栈操作 { if(s->top==-1) return FALSE; else { *x=s->elem[s->top]; s->top--; return TRUE; } } void conversion(int N) { int x; SeqStack STA; InitStack(&STA); printf("/nplease input the value:"); scanf("%d",&x); while(x!=0) { Push(&STA,x%N); x=x/N; } printf("/nthe result is:"); while(!IsEmpty(&STA)) { Pop(&STA,&x); printf("%d",x); } } void main() { int max; printf("please input the conversion number(only 2,8):"); scanf("%d",&max); conversion(max); printf("/n"); }