#include "stdafx.h"
#define Maxsize 100
include
typedef int datatype;
typedef struct
{
int stack[Maxsize];
int top;
}SeqStack;
SeqStack*InitStack()
{
SeqStack * S;
S=(SeqStack *)(sizeof(SeqStack));
if(!S)
{
printf("空间不足");
return NULL;
}
else {
S->top=0;
return S;
}
}
SeqStack *push (SeqStack *S,int x)
{
if (S->top ==Maxsize)
{
printf("the stack is overflow!\n");
return NULL;
}
else
{
S->stack[S->top]=x;
S->top++;
return S;
}
}
int StackEmpty(SeqStack *S)
{
if (S->top==0)
return 1;
else
return 0;
}
int pop(SeqStack *S)
{
int y;
if (S->top==0)
{
printf("the stack is empty!\n");return 0;
}
else {
S->top--;
y=S->stack[S->top];
return y;
}
}
void conversion(int N,int r)
{
int x=N,y=r;
SeqStack *s;
s=InitStack();
while(N!=0)
{
push(s,N%r);
N=N/r;
}
printf("\n十进制数 %d所对应的 %d进制数是:" "x,y");
while(!StackEmpty(s))
printf("%d",pop(s));
printf("\n");
}
int main();
{
int n;
int r;
printf(" 请输入任意一个十进制整数及其所需转换的二至九间的任一进制数 :\n");
scanf("%d%d",&n,&r);
conversion(n,r);
}