#include<stdio.h>
#define MAXSIZE 100
typedef int datatype;
typedef struct{
datatype a[MAXSIZE];
int top;
}sequence_stack;
void init_seqstack(sequence_stack *st)
{ st->top=0;
}
void printseqstack(sequence_stack *st,int m)
{ int i;
i=st->top-1;
while(i>=0)
{ if(m==16)/*十进制转换为十六进制*/
{ switch(st->a[i])
{ 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;
case 9:
case 8:
case 7:
case 6:
case 5:
case 4:
case 3:
case 2:
case 1:
case 0: printf("%d",st->a[i]);break;
}
}
else printf("%d",st->a[i]);
i--;
}
}
void jzhzhh(sequence_stack *st,int n,int m)/*堆栈存放各个数*/
{ int i=0;
while(n!=0)
{ st->a[i]=n%m;
n=n/m;
st->top++;
i++;
}
}
main()
{ int n,m;
sequence_stack p;
printf("n=");
scanf("%d",&n);
printf("m=");
scanf("%d",&m);
init_seqstack(&p);
jzhzhh(&p, n, m);
printseqstack(&p,m);
printf("\n");
getch();
}
/*以前写的,不知道能不能用了.10进制转(<10或16)进制数*/