#define SIZE 100
typedef struct
{
int data[SIZE];
int top;
}Stack;
int main()
{
int num, n;
printf("请输入一个十进制数值\n");
scanf("%d", &num);
printf("请输入你要转成的进制\n");
scanf("%d", &n);
Stack* ps;
ps = (Stack*)malloc(sizeof(Stack) * SIZE);
ps->top = 0;
while (num)
{
if ((ps->top + 1) % SIZE != 0)
{
ps->top++;
ps->data[ps->top] = num % n;
num /= n;
}
}
printf("转换后为: ");
while (ps->top != 0)
{
int x = ps->data[ps->top];
printf("%d", x);
ps->top--;
}
return 0;
}
数据结构数值的转换(顺序栈)
最新推荐文章于 2024-10-02 10:19:33 发布