标题:数制转换(错在那)
取消只看楼主
我loveC
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-2-28
 问题点数:0 回复次数:0 
数制转换(错在那)
#include<malloc.h>
#include<stdio.h>
#define STACK_INIT_SIZE 100
#define STACKINCERMENT 10
#define OK 1
#define OVERFLOW -1
#define ERROR 0
typedef struct{
    int *base;
    int *top;
    int stacksize;}sqstack;
  int initstack(sqstack *s)
 {  s->base=(int*)malloc(STACK_INIT_SIZE*sizeof(int));
    s->top=s->base;
    s->stacksize=STACK_INIT_SIZE;
    return OK;}
  void push(sqstack *s ,int e)
 { if(s->top-s->base>=s->stacksize)
{  s->base=(int*)realloc(s->base,(s->stacksize+STACKINCREMENT)*sizeof(int));
if(!s->base)exit(OVERFLOW);
 s->top=s->base+s->stacksize;
s->stacksize+=STACKINCREMENT;}
 *(s->top++)=e;}
 void pop(spstack *s,int *e)
{ if(s->top==s->base)
   return ERROR;
   *e=*(--s->top);}
main()
 {int n,m,e;
  initstack(&s);
 clrscr();
 scanf("%d%d",&n,&m);
 while(n){ push(&s,n%m);
 n=n/m;}
  while(!(s.top==s.base))
 {pop(&s,&e);
  if(e<=q)
  printf("%d",e);
  else
  printf("%c",e-10+'A');
}
 }
搜索更多相关主题的帖子: 数制 
2008-03-29 14:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-205996-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.317736 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved