首页 数制转换 C语言

数制转换 C语言

举报
开通vip

数制转换 C语言数制转换 C语言 #include #include #define N 10 #define INITIAL 20 typedef struct zhan { int *base; int *top; int size; }; void initzhan(struct zhan *s) { s->base = (int*)malloc(INITIAL * sizeof(int)); if(!s->base) exit(0); s->top = s->base; s->size = ...

数制转换 C语言
数制转换 C语言 #include #include #define N 10 #define INITIAL 20 typedef struct zhan { int *base; int *top; int size; }; void initzhan(struct zhan *s) { s->base = (int*)malloc(INITIAL * sizeof(int)); if(!s->base) exit(0); s->top = s->base; s->size = INITIAL; return; } void clearzhan(struct zhan *s) { if(s->top == s->base) return; s->top = s->base; return; } void push(struct zhan *s, int e) { if(s->top - s->base >= s->size) { s->base = (int*)realloc(s->base,(s->size + N)* sizeof(int)); if(!s->base) exit(0); s->top = s->base + s->size; s->size += N; } *(s->top)++=e; return; } void pop(struct zhan *s) { int e; if(s->top == s->base) return ; e = *--s->top; printf("%d",e); } void conversion( int a) { struct zhan s; initzhan(&s); while(a) { push(&s, a%8); a = a/8; } while(s.top != s.base) pop(&s); clearzhan(&s); } void main() { int n; printf("\n please input a num(radix 10):"); scanf_s("%d",&n); printf("\n after conversion (10)%d to 8: ",n); conversion(n); printf("\n"); }
本文档为【数制转换 C语言】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_594886
暂无简介~
格式:doc
大小:22KB
软件:Word
页数:3
分类:初中语文
上传时间:2017-09-27
浏览量:29