125478963 2023-03-30 15:10 采纳率: 0%
浏览 65

/* 以下程序实现的功能为对于输入的任意一个非负十进制整数,打印输出与其等值的八进制数 */最后main函数里要填什么

/* 以下程序实现的功能为对于输入的任意一个非负十进制整数,打印输出与其等值的八进制数 */
最后main函数里要填什么?

#include<string.h>
 #include<ctype.h>
 #include<malloc.h> 
 #include<limits.h> 
 #include<stdio.h> 
 #include<stdlib.h> 
 #include<io.h> 

 #include<process.h> /* exit() */
 #define TRUE 1
 #define FALSE 0
 #define OK 1
 #define ERROR 0
 #define INFEASIBLE -1
 #define OVERFLOW -2
 
 typedef int Status; 
 typedef int Boolean; 
 typedef int SElemType; 

/*栈的顺序存储表示 */
 #define STACK_INIT_SIZE 10 
 #define STACKINCREMENT 2
 
 typedef struct
 {
    SElemType *base;
    SElemType *top;
    int stacksize;                //填写语句
    
   
 }SqStack;

Status InitStack(SqStack *S)   //初始化顺序栈 
{
    (*S).base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType));
    if(!(*S).base) exit(OVERFLOW);
    (*S).top=(*S).base;
    (*S).stacksize=STACK_INIT_SIZE;
    return OK;
}

Status DestroyStack(SqStack *S)
 { 
   free((*S).base);
   (*S).base=NULL;
   (*S).top=NULL;
   (*S).stacksize=0; 
   return OK;
 }

 Status ClearStack(SqStack *S)
 {                     
    S->top = S->base;                   //填写一条语句
    return OK;
 }

 Status StackEmpty(SqStack S)
 { 
   if(S.top==S.base||S.top<S.base)         //括号内补充完整
     return TRUE;
   else
     return FALSE;
 }

 int StackLength(SqStack S)
 { 
   return S.top-S.base;
 }

 Status GetTop(SqStack S,SElemType *e)
 {
   if(S.top>S.base)
   {
     *e=*(S.top-1);
     return OK;
   }
   else
     return ERROR;
 }

 Status Push(SqStack *S,SElemType e)
 {
   if((*S).top-(*S).base >= (*S).stacksize)    //补充完整判断条件表达式
   {
     (*S).base = (SElemType *)realloc ((*S).base,((*S).stacksize + STACKINCREMENT)*sizeof(SElemType));                                                             //填写一条语句
     if(!(*S).base)
       exit(OVERFLOW); 
     (*S).top= (*S).base + (*S).stacksize; 
     (*S).stacksize +=STACKINCREMENT;                                   //填写两条语句
     
   }
   *((*S).top)++=e;
   return OK;
 }

 Status Pop(SqStack *S,SElemType *e)
 { 
    if((*S).top==(*S).base )    //补充完整判断条件表达式
     return ERROR;
   *e=*--(*S).top;
   return OK;
 }
 void conversion() /* 算法3.1 */
 { 
   SqStack s;
   unsigned n;
   SElemType e;
   InitStack(&s);
   printf("n(>=0)=");
   scanf("%u",&n); 
   while(n) 
   {
     Push(&s,n%8);                  //填写一条语句
     n=n/8;
   }
   while(!StackEmpty(s)) 
   {
     Pop(&s,e);                  //填写一条语句
     printf("%d",e); 
   }
   printf("\n");
 }

 main()
 {
                         //填写一条语句
   getch();         
 }


  • 写回答

2条回答 默认 最新

  • threenewbee 2023-03-30 15:22
    关注

    conversion();

    评论

报告相同问题?

问题事件

  • 创建了问题 3月30日

悬赏问题

  • ¥20 gitlab 中文路径,无法下载
  • ¥15 用动态规划算法均分纸牌
  • ¥30 udp socket,bind 0.0.0.0 ,如何自动选取用户访问的服务器IP来回复数据
  • ¥15 关于树的路径求解问题
  • ¥15 yolo在训练时候出现File "D:\yolo\yolov5-7.0\train.py"line 638,in <module>
  • ¥30 戴尔inspiron独显直连
  • ¥15 进行一项代码设计遇到问题
  • ¥15 Mutisim中关于74LS192N计数器芯片设计(计数器)
  • ¥50 fastadmin后台无法删除文件
  • ¥15 oracle查询Socket read timed out错误