热门

最新

红包

立Flag

投票

同城

我的

发布
weixin_56761270
三七865
4 年前
trueweixin_56761270

求大佬,为什么这个十进制转化成八进制,八进制始终为0
#include<stdio.h>
#include<malloc.h>
#define MaxSize 50
typedef int ElemType;
typedef struct{
ElemType data[MaxSize];
int top;
}SqStack;
void InitSqStack(SqStack * &s)
{
s=(SqStack * )malloc(sizeof(SqStack));
s->top=-1;
}
void DestroyStack(SqStack * &s)
{
free(s);
}
bool StackEmpty(SqStack * s)
{
return(s->top==-1);

}
bool Push(SqStack * &s,ElemType e)
{
if(s->top==MaxSize-1)
s->top++;
s->data[s->top]=e;
return true;
}
bool Pop(SqStack * &s,ElemType &e)
{
if(s->top==-1)
return false;
e=s->data[s->top];
s->top--;
return true;
}
bool GetTop(SqStack *s,ElemType &e)
{
if(s->top==-1)
return false;
e=s->data[s->top];
return true;
}
void DisStack(SqStack *s){
int e;
while(true){
Pop(s,e);
printf("%d",e);
if(s->top==-1){
break;
}
}
}
int main(void)
{
SqStack *s;
ElemType e;
InitSqStack(s);
int x;
printf("请输入一个十进制的整数:");
scanf("%d",&x);
while(x>0){
Push(s,x%8);
x=x/8;
}
printf("其八进制数为: ");
DisStack(s);

printf("\n");

}

CSDN App 扫码分享
分享
评论
点赞
打赏
  • 复制链接
  • 举报
下一条:
立即登录