进制转换编程

来源:百度知道 编辑:UC知道 时间:2024/05/17 23:04:54
用栈来实现十进制数向八进制数转换
用C,谢谢

void conversion()
{
pSqStack S;
SElemType e;
int n;
InitStack(&S);
printf("Input a number to convert to OCT:\n");
scanf("%d",&n);
if(n<0)
{
printf("\nThe number must be over 0.");
return;
}
if(!n) Push(S,0);
while(n)
{
Push(S,n%8);
n=n/8;
}
printf("the result is: ");
while(!StackEmpty(*S))
{
Pop(S,&e); printf("%d",e);
}
}