#include "stdio.h"
#include"stdlib.h"
#define true 1
#define false 0
#define maxsize 50
struct sqlist{ int data[maxsize];
int top;
}
conversion(int n,int r)
{int x;
struct sqlist *s;
s=(struct sqlist*)malloc(sizeof(struct sqlist));
s->top=-1;
while(n!=0)
{ m=n%r;
switch(m)
{ case 10:m='A';break;
case 11:m='B';break;
case 12:m='C';break;
case 13:m='D';break;
case 14:m='E';break;
case 15:m='F';break;
default:m=m;break;
}
{push(s,n%r);
n=n/r;}
while(!empty(s))
{x=pop(s);
printf("%d",x);}
switch(r)
{
case 2:printf("B");break;
case 8:printf("Q");break;
case 16:printf("H");break;
}
}
int push(struct sqlist *s,int e)
{if(s->top==maxsize-1)
return false;
s->top++;
s->data[s->top]=e;
return true;}
int pop(struct sqlist *s,int e)
{ if(s->top==-1)
return false;
e=s->data[s->top];
s->top--;
return e;
}
int empty(struct sqlist *s)
{ return(s->top==-1);
}
main()
{int n,r,m;
printf("输入要转换的数字n:");
scanf("%d",&n);
printf("输入要转换的进制r:");
scanf("%d",&r);
conversion(n,r);
}
#include"stdlib.h"
#define true 1
#define false 0
#define maxsize 50
struct sqlist{ int data[maxsize];
int top;
}
conversion(int n,int r)
{int x;
struct sqlist *s;
s=(struct sqlist*)malloc(sizeof(struct sqlist));
s->top=-1;
while(n!=0)
{ m=n%r;
switch(m)
{ case 10:m='A';break;
case 11:m='B';break;
case 12:m='C';break;
case 13:m='D';break;
case 14:m='E';break;
case 15:m='F';break;
default:m=m;break;
}
{push(s,n%r);
n=n/r;}
while(!empty(s))
{x=pop(s);
printf("%d",x);}
switch(r)
{
case 2:printf("B");break;
case 8:printf("Q");break;
case 16:printf("H");break;
}
}
int push(struct sqlist *s,int e)
{if(s->top==maxsize-1)
return false;
s->top++;
s->data[s->top]=e;
return true;}
int pop(struct sqlist *s,int e)
{ if(s->top==-1)
return false;
e=s->data[s->top];
s->top--;
return e;
}
int empty(struct sqlist *s)
{ return(s->top==-1);
}
main()
{int n,r,m;
printf("输入要转换的数字n:");
scanf("%d",&n);
printf("输入要转换的进制r:");
scanf("%d",&r);
conversion(n,r);
}