#include <stdio.h>
#include <stdlib.h>
#define MAX 100
typedef int Elemtype;
typedef int status;
typedef struct
{
Elemtype base[MAX];
int top;
}Sqstack;
void initstack(Sqstack &s)
{
s.top=-1;
}
void push(Sqstack &s,int e)
{
s.top++;
s.base[s.top]=e;
}
void output(Sqstack s)
{
int i;
for(i=s.top;i>=0;i--)
{
printf("%d",s.base[i]);
}
}
int gettop(Sqstack s,int e)
{
e=s.base[s.top];
return e;
}
void delstack(Sqstack &s)
{
s.base[s.top--]=NULL;
}
int main()
{
Sqstack s;
initstack(s);
printf("请输入一个十进制数:");
int num;
scanf("%d",&num);
printf("请输入你要转换的进制:");
int R;
scanf("%d",&R);
int temp;
while(num!=0)
{
temp=num%R;
push(s,temp);
num/=R;
}
printf("%d转换为%d进制后的值为:",num,R);
output(s);
printf("\n");
return 0;
}
0