/********数值转换,八进制转十进制*********/
#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));
数值转换,八进制转十进制(附源代码并通过测试)
最新推荐文章于 2022-05-15 19:12:08 发布
本文详细介绍了如何将八进制数转换为十进制数,并提供了一份通过测试的源代码,帮助理解转换过程。
摘要由CSDN通过智能技术生成