标签:break top bsp return str fine clu include turn
10进制转任何进制
#include<stdio.h>
#include<stdlib.h>
#define maxSize 30
typedef int DataType;
typedef struct{
DataType data[maxSize];
int top;
}Seqstack;
int push(Seqstack &s,DataType x){
if(s.top==maxSize-1) return 0;
s.data[++s.top]=x;
return 1;
}
int pop(Seqstack &s){
int x;
if(s.top==-1) return 0;
x=s.data[s.top--];
return x;
}
int main(){
Seqstack s;
s.top=-1;
int a,b,i,x;
printf("输入需转化的十进制数:");
scanf("%d",&a);
printf("转化进制为:");
scanf("%d",&b);
while(a>=b){
x=a%b;
a=a/b;
push(s,x);
}
push(s,a);
if(b>=10){
while(s.top!=-1){
x=pop(s);
switch(x){
case 1 : case 2 : case 3 : case 4: ; case 5: ; case 6: ; case 7: ; case 8: ; case 9: ; case 0: ;
printf("%d",x);break;
case 10: printf("a");break;
case 11:printf("b");break;
case 12: printf("c");break;
case 13: printf("d");break;
case 14: printf("e");break;
case 15: printf("f");break;
}
}
}
else
while(s.top!=-1){
x=pop(s);
printf("%d",x);
}
}
标签:break top bsp return str fine clu include turn
原文地址:https://www.cnblogs.com/chenfengdian/p/10755562.html