数值转换,八进制转十进制(附源代码并通过测试)

本文详细介绍了如何将八进制数转换为十进制数,并提供了一份通过测试的源代码,帮助理解转换过程。
摘要由CSDN通过智能技术生成
/********数值转换,八进制转十进制*********/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define STACK_INIT_SIZE 100
#define STACKINCRECE 10

typedef struct
{
    int *top;
    int *base;
    int stacksize;
}stack;

int main()
{
    //构造空栈
    void InitStack(stack *s);
    //Push入栈
    void Push(stack *s, int e);
    //Pop出栈
    int Pop(stack *s, int e);
    //定义
    stack s;
    int num;
    int e;

    InitStack(&s);
    // 1. 输入要转换的数
    printf("Please input the num u want conversion:");
    scanf("%d",&num);
    // 2. 当num/8为真则取余并入栈
    do
    {
        Push(&s,num%8);
        num /= 8;
    }while(num);
    // 3. num/8为0则出栈并输出结果
    do
    {
        printf("%d",Pop(&s, e));
    }while(s.base != s.top);

    return 0;
}

void InitStack(stack *s)
{
    // 动态申请内存空间
    s->base = (int *)malloc(STACK_INIT_SIZE * sizeof(int));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值