当前位置:网站首页>Input a decimal data, convert to 8, using the sequence stack
Input a decimal data, convert to 8, using the sequence stack
2022-06-30 10:35:00 【Fat Xiao Deng】
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
// Sequence stack management structure :
typedef struct order_stack
{
int *stack; // Stack space start address
int size; // The size of the stack
int top; // To the top of the stack
}Os, *P_os;
// Initialization of sequence stack
P_os init_order_stack(int size)
{
P_os os = (P_os)malloc(sizeof(Os));
if (os != NULL)
{
os->stack = calloc(size, sizeof(int));
os->size = size;
os->top = 0; // Generally, the top of the stack is initialized as -1
}
return os;
}
// Stack in sequence
bool in_stack(P_os os, int data)
{
if (os == NULL || os->size == os->top+1)
{
printf(" The stack does not exist or is full \n");
return false;
}
os->stack[os->top] = data;
os->top++;
return true;
}
// Sequential stack out
bool out_stack(P_os os, int *data)
{
if (os == NULL)
{
printf(" Stack does not exist \n");
return false;
}
os->top--;
*data = os->stack[os->top];
printf("%d", *data);
os->stack[os->top] = 0;
}
void octal_show(P_os os,int n)// Convert to octal number
{
while(n>0)
{
in_stack(os,n%8);
n/=8;
}
int m8;
while(!(os->top==0))
{
out_stack(os,&m8);// The data is printed out of the stack , No need to print later
}
printf("\n");
}
int main(int argc, char const *argv[])
{
int n;
P_os os = init_order_stack(10);
printf(" Please enter a decimal integer :\n");
scanf("%d",&n);
printf(" Convert to octal integer as :\n");
octal_show(os,n);
return 0;
}
For reference only , It's convenient for you to check , If there is a mistake , Please comment and inform , thank you !
边栏推荐
- 乡村振兴公益基金启动暨古茶树非遗保护公益行发布
- The preliminary round of the sixth season of 2022 perfect children's model Hefei competition area was successfully concluded
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验1 跑马灯(RGB)实验(学习笔记)
- Gd32 RT thread PWM drive function
- Koreano essential creates a professional style
- “昆明城市咖啡地圖”活動再度開啟
- Skill combing [email protected] somatosensory manipulator
- 半钢同轴射频线的史密斯圆图查看和网络分析仪E5071C的射频线匹配校准
- 技能梳理[email protected]+阿里云+nbiot+dht11+bh1750+土壤湿度传感器+oled
- Yixian e-commerce released its first quarterly report: adhere to R & D and brand investment to achieve sustainable and high-quality development
猜你喜欢
[email protected] voice module +stm32+nfc"/>Skill combing [email protected] voice module +stm32+nfc

"Kunming City coffee map" activity was launched again

“昆明城市咖啡地图”再度开启,咖啡拉近城市距离

那个程序员,被打了。

Compétences Comb 27 @ Body sense Manipulator

Basic MySQL operation commands of database

逸仙電商發布一季報:堅持研發及品牌投入,實現可持續高質量發展

Apple's 5g chip was revealed to have failed in research and development, and the QQ password bug caused heated discussion. Wei Lai responded to the short selling rumors. Today, more big news is here

孙安民作品《莲花净心》数字藏品上线长城数艺

今晚19:00知识赋能第2期直播丨OpenHarmony智能家居项目之控制面板界面设计
随机推荐
长城数艺数字藏品平台发布创世徽章
GD32 RT-Thread OTA/Bootloader驱动函数
超长干货 | Kubernetes命名空间详解
"Kunming City coffee map" was opened again, and coffee brought the city closer
Turn to cartoon learning notes
Gd32 RT thread RTC driver function
MySQL log management, backup and recovery of databases (1)
Why can't you rob scientists of NFT
Overview of currency
Who should the newly admitted miners bow to in front of the chip machine and the graphics card machine
ArcGIS Pro scripting tool (5) - delete duplicates after sorting
今晚19:00知识赋能第2期直播丨OpenHarmony智能家居项目之控制面板界面设计
GNN hands on practice (II): reproduction graph attention network gat
Gd32 RT thread ota/bootloader driver function
孙安民作品《莲花净心》数字藏品上线长城数艺
MySQL log management, backup and recovery of databases (2)
“昆明城市咖啡地图”再度开启,咖啡拉近城市距离
Eth is not connected to the ore pool
Auto Seg-Loss: 自动损失函数设计
技能梳理[email protected]+阿里云+nbiot+dht11+bh1750+土壤湿度传感器+oled