用堆栈来转换进制数

#include<stdio.h>
#define MAX 20
struct stack
{
int a[MAX];
int top;
}op;
void main()
{
int a,n;
op.top=0;
printf("please input a:\n");
scanf("%d",&a);
printf("你想转换成几进制数?\n");
scanf("%d",&n);
while(a)
{
  op.a[op.top++]=a%n;
  a=a/n;
}
op.top--;
printf("对应的%d进制数为:\n",n);
while(op.top>=0)
  printf("%d",op.a[op.top--]);
printf("\n");
}

posted @ 2017-09-22 23:09  lijianzhq  阅读(225)  评论(0)    收藏  举报