标签:
#include <stdio.h> #define STACKSIZE 110 #define OK 1 #define TRUE 1 #define FALSE 0 int flag; typedef int ElemType; typedef int Status; typedef struct { ElemType data[STACKSIZE]; int top; }SeqStack; void InitStack(SeqStack *s) { (*s).top = 0; } Status StackFull(SeqStack s) { if(s.top==STACKSIZE-1) return FALSE; return TRUE; } void Push(SeqStack *s, ElemType p) { if(!StackFull(*s)) { printf("OverFlow\n"); flag=1; } (*s).data[(*s).top]=p; (*s).top++; } Status StackEmpty(SeqStack s) { if(s.top==0) return FALSE; return TRUE; } Status Pop(SeqStack *s,ElemType *p) { if(!StackEmpty(*s)) return FALSE; (*s).top--; *p=(*s).data[(*s).top]; return TRUE; } void conversion() { ElemType n, m; int p; SeqStack s; flag = 0; printf("请输入一个数字:\n"); scanf("%d", &n); printf("请输入需要转换的数制:\n"); scanf("%d", &m); InitStack(&s); while(n) { Push(&s, n%m); n = n/m; } if(!flag) { while(StackEmpty(s)==1) { Pop(&s, &p); printf("%d", p); } printf("\n"); } } int main() { conversion(); return 0; }
标签:
原文地址:http://www.cnblogs.com/daydayupacm/p/5980095.html