明明就一个scanf,但让输入两次,而且最后出不来想要的结果。有人能帮我看一下吗
#include <stdio.h>
#include <stdlib.h>
#define MaxSize 100
typedef int ElemType;
typedef struct
{
ElemType data[MaxSize];
int top;
}SqStack;
/初始化/
void InitStack(SqStack *&s)
{
s->top=-1;
}
/销毁/
void DestroyStack(SqStack *&s)
{
free(s);
}
/判断栈是否为空/
int StackEmpty(SqStack *s)
{
return(s->top==-1);
}
/进栈/
int Push(SqStack *s,ElemType e)
{
if(s->top==MaxSize-1)
return 0;
s->top++;
s->data[s->top]=e;
return 1;
}
/出栈/
bool Pop(SqStack *s,ElemType e)
{
if(s->top==-1)
return 0;
e=s->data[s->top];
s->top--;
return 1;
}
/取栈顶元素/
int GetTop(SqStack *s,ElemType e)
{
if(s->top==-1)
return 0;
e=s->data[s->top];
return 1;
}
/数制转换/
void Conversion(int N)
{
SqStack *s=(SqStack *)malloc(sizeof(SqStack));
InitStack(s);
int e;
while(N)
{
Push(s,N%2);
N=N/2;
}
while (!StackEmpty(s))
{
Pop(s,e);
printf("%d",e);
}
}
/主函数/
int main()
{
int num;
printf("请输入要转化的数值:");
scanf("%d\n",&num);
Conversion(num);
return 0;
}