用栈实现进制转换,该如何处理
用栈实现进制转换
怎么有点错误 帮忙改一下 改成可以运行的
#include <stdio.h>
#include <malloc.h>
#include <conio.h>
typedef int SElemType;
Status visit(SElemType * e)
{
printf( " %d ", *e);
}
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);
}
}
main()
{
printf( "\n\n\n\n ");
conversion();
getch();
printf( "\n\nWelcome to visit http://zmofun.yeah.net ! ");
}
------解决方案--------------------
这样补程序也太……
那函数至少实现什么功能得告诉大家吧!
怎么有点错误 帮忙改一下 改成可以运行的
#include <stdio.h>
#include <malloc.h>
#include <conio.h>
typedef int SElemType;
Status visit(SElemType * e)
{
printf( " %d ", *e);
}
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);
}
}
main()
{
printf( "\n\n\n\n ");
conversion();
getch();
printf( "\n\nWelcome to visit http://zmofun.yeah.net ! ");
}
------解决方案--------------------
这样补程序也太……
那函数至少实现什么功能得告诉大家吧!