# include <stdio.h>
# include <stdlib.h>
# include <malloc.h>
# define Init_size 100
# define New_size 10
typedef struct {
int *base ,* top ;
int size;
} SqStack;
int InitStack (SqStack *S)
{
S->base=(int* )malloc (Init_size *sizeof(int) );
if (!S->base)
return (1);
else {
S->top =S->base;
S->size=Init_size;
return (0);
}
}
int Push (SqStack *S,int ch){
if (S->top-S->base>=S->size) {
S->base=(int *)realloc (S->base, (S->size+New_size)*sizeof (int));
if (!S->base)
{
return (1);
}
S->top=S->base+S->size;
S->size +=New_size;
}
*S->top=ch;
S->top++;
}
int Pop (SqStack *S)
{
if (S->top!=S->base)
return (*(--S->top));
}
void ClearStack (SqStack *S) {
if (S->top!=S->base)
S->top=S->base;
}
main (){
SqStack s;
int num,jz,a,result;
if (InitStack (&s))
{
puts ("fail!!\n");
exit (0);
}
ClearStack (&s);
puts ("please input a operation num\n");
scanf ("%d",&num);
if (num<0)
result=-num;
printf ("please input which JIN Zhi do you want \n");
scanf ("%d",&jz);
while (result)
{ a=result%jz ;
Push (&s,a);
result=result/jz;
}
if (num<0)
printf ("-");
while (s.top!=s.base){
printf ("%d",Pop(&s));
}
printf ("\n");
}
无论我输入什么结果都是一样的
怎么会这样
是算法错了吗