#include"stdio.h"
#include"malloc.h"
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define OK 1
#define OVERFLOW -2
typedef struct{
int *base;
int *top;
int stacksize;
}SqStack;
SqStack S;
int Initstack(SqStack s)
{
s.base=(int *)malloc(STACK_INIT_SIZE * sizeof (int));
if(!s.base)exit(OVERFLOW) ;
s.top=s.base;
s.stacksize=STACK_INIT_SIZE;
return OK;
}
int push(SqStack s,int e)
{
if(s.top-s.base>=s.stacksize)
{s.base=(int *)realloc(s.base,(s.stacksize+STACKINCREMENT) * sizeof (int));
if(!s.base)exit(OVERFLOW) ;
s.top=s.base+s.stacksize;
s.stacksize+=STACKINCREMENT;
}
*s.top=e;
s.top++;
return OK;
}
main()
{int N,d;
Initstack(S);
printf("Input The Number changed:\n");
scanf("%d",&N); /*输入要转换的数*/
printf("Input The changed zhidu:\n");
scanf("%d",&d); /*输入要转换的进制数*/
while(N)
{
push(S,N%d);
N=N/d ;
}
while (S.top!=S.base)
{
printf("%d",*(--S.top));
}
getch();
}