问题不难,时间紧张。

利用栈这种数据结构,编程实现将一个十进制整数n转换成r进制数(r的取值为2~9)。
要求:
1、栈的存储结构为顺序栈,不能是链栈。
2、使用辗转相除法实现数制的转换。

望采纳~

#include <stdio.h>
#include <stdlib.h>
 
#define ERROR 0
#define OK 1
#define  MAXSIZE  20
typedef int ElemType;
 
typedef struct Sqstack{
    ElemType *top;
    ElemType *base;
    ElemType stacksize;
}stack;
 
/*Function:栈初始化 */ 
int Initstack04(stack *s){
    s->base=(ElemType *)malloc(MAXSIZE*sizeof(ElemType));//申请空间
    if(s->base==NULL) {
        printf("栈创建失败!");
        return ERROR; 
    }
   s->top=s->base;
   s->stacksize=MAXSIZE;
   printf("栈创建成功!"); 
   return OK;
}
/*Function:入栈*/ 
int Push04(stack *s,ElemType e){
    if(s->top-s->base==MAXSIZE){
        return ERROR;
    }
    *s->top++=e;
    return OK;
} 
/*Function:出栈*/ 
int Pop04(stack *s){
    if(s->top==s->base){
        printf("栈为空栈!\n");
        return ERROR;
    }
    s->top--;
    printf("%d ",*s->top);
    return OK;
}
/*Function:进制转换*/
void transition(stack *s){
     int n,m;
     printf("请输入您要转换的数字:\n");
     scanf("%d",&m);
     printf("请输入您要转换的进制:\n");
     scanf("%d",&n);
     while(m){
         Push04(s,m%n);//余数入栈 
         m=m/n;
        }
     printf("转换结果为:\n");
     while(s->top!=s->base){//输出 
         Pop04(s);
     }
}
void main(){
    stack s;
    Initstack04(&s);
    transition(&s);
}


img

楼上的很好