#include<stdio.h>
#include<stdlib.h>
#define maxs 100
typedef struct stack{
int list[maxs];
int top;
}stack;
stack* initstack(){ //初始化堆栈
stack* s=(stack*)malloc(sizeof(stack));
s->top = -1;
return s;
}
int push(stack *s,int a){ //入栈与判断
if(s->top>=maxs-1){
printf("堆栈已满!");
return 0;
}
else{
return s->list[++s->top]=a;
}
}
int pop(stack *s){ //出栈与判断
if(s->top==-1){
return -1;
}else
return s->list[s->top--];
}
int main()
{
int m,n,i=0,num;
stack *s =initstack();
printf("请输入转换数和转换进制用空格隔开\n");
scanf("%d %d",&m,&n);
while(m>0){ //算法都在下面没有再写函数了555
push(s,m%n);
m=m/n;
i++;
}
while(i>0){
num =pop(s);
if(num==10)
printf("A");
else if(num==11)
printf("B");
else if(num==12)
printf("C");
else if(num==13)
printf("D");
else if(num==14)
printf("E");
else if(num==15)
printf("F");
else
printf("%d",num);
i--;
}
}
04-29
3518
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)