convert.c

来自「数据结构 c语言 教程」· C语言 代码 · 共 50 行

C
50
字号
#include<stdio.h>
#include<malloc.h>
#include<conio.h>

typedef int SElemType;

#include "stack.h"

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 !");
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?