栈的应用-进制转化

#include<stdio.h>
#include<stdlib.h>
#define Maxsize 100
typedef int SelmType;
typedef struct{
    SelmType stack[100];
    int top;
}SqStack;
void InitStack(SqStack *S) {
    S->top=0;
}
int StackEmpty(SqStack *S) {
    if(S->top==0)
        return 1;
    else
        return 0;
}
int GetTop(SqStack S,SelmType e) {
    if(S.top>0){
        e=S.stack[S.top-1];
        return e;
    }
    else
        return -1;


}
void Push(SqStack *S,SelmType e){
    if((S->top)>100){
        printf("Stack overflow");}
    else
        S->stack[S->top++]=e;
        
    
    }

void Pop(SqStack *S,SelmType e) {
    if(S->top==0){
        printf("Stack underflow");}
    else
        e=S->stack[--S->top];
    
    }
void conver(SelmType e,SelmType n){
    int i,L;
    int m=e;
    SqStack S;
    InitStack(&S);
    do{
        i=e%n;
        Push(&S,i);
        e/=n;
    }while(e);
    printf("%d转化成%d进制等于",m,n);
    while(S.top!=0){
        
        L=GetTop(S,n);
        if(L!=-1){
            printf("%d",L);}
    S.top--;
    }}
    int main(){
        SelmType i,n;
        printf("输入一个十进制");
        scanf("%d",&i);
        printf("转化为几进制");
        scanf("%d",&n);
        conver(i,n);
    
    }
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值