当前位置:网站首页>C语言——printf打印进制前缀
C语言——printf打印进制前缀
2022-06-29 15:45:00 【Please trust me】
问题
这里与大家分享一个小技巧,关于一些题目要求我们打印如下格式
八进制: 020 0144 0213
十六进制:0x231 0x231 0x64
很简单,我们只需要在最后打印的时候,对打印的变量进行声明打印类型即可。
八进制:%o
十六进制:%x
可惜最后结果不对!!!
如下
我们打印出来的结果没有进制的前缀
怎么办呢?
解决
使用C语言说明符,来打印这些前缀
代码
#include<stdio.h>
/* 八进制: %#o 十六进制: %#x or %#X */
int main(void)
{
int x=100;
printf("dec = %d; octal = %#o ; hex = %#x or hex = %#X \n",x,x,x);
return 0;
}
结果

也算是一个小技巧吧,万一哪天有用呢
边栏推荐
- How to embed iframes in WordPress
- Leetcode-234-palindrome linked list
- 墨天轮“高可用架构”干货文档分享(含Oracle、MySQL、PG资料124篇)
- 等保测评结论为差,是不是表示等保工作白做了?
- Alipay "security lock" was selected as an excellent case in the "child care program" of the ICT Institute: more than 330000 users have opened game protection
- Autodesk Revit 2023软件安装包下载及安装教程
- 基于JSP实现毕业设计选题系统
- A. Beat The Odds
- leetcode:42. 接雨水【双指针很优雅】
- Three development trends of enterprise application viewed from the third technological revolution
猜你喜欢

wallys/m.2/Adapter card(one pcie1x to 4 x Mini PCIE)

LeetCode-470-用Rand7()实现Rand10()

golang操作etcd

Stlink troubleshooting

火山引擎入选国内首个《边缘计算产业全景图》

Cmake learning-2

防范企业数据泄露,就用网络安全产品堡垒机!

three.js和高德地图结合引入obj格式模型-效果演示

2022 OpenVINO DevCon 大揭秘!英特尔携众多合作伙伴深化开发者生态建设,释放AI产业创新潜能

It is expected to significantly improve the computational performance of integrated photonic circuits. The Tsinghua team proposed a diffraction pattern neural network framework
随机推荐
Alipay "security lock" was selected as an excellent case in the "child care program" of the ICT Institute: more than 330000 users have opened game protection
按键精灵打怪学习-窗口绑定保护技能和点击技能
89. (cesium article) cesium aggregation diagram (custom picture)
Stlink troubleshooting
有哪些顶级水平的中国程序员?
How can I repair a slow WordPress website?
CVPR 2022 | 大幅减少零样本学习所需的人工标注,马普所和北邮提出富含视觉信息的类别语义嵌入
El table column row button anti weight control loading
Taro2.* 小程序配置分享微信朋友圈
mysql报错:Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column
卫龙辣条第三次冲刺上市:业绩增速下滑,刘卫平、刘福平提前套现
BS-GX-017基于SSM实现的在线考试管理系统
Detailed explanation of list set
作为开发人员,无代码开发平台 iVX 你有必要了解一下
Science:大脑中睡眠的相互关联原因和结果
C language big job - Matching System
A. Marathon
Three development trends of enterprise application viewed from the third technological revolution
发明了杀毒软件之后,他选择做一个极品混混
#夏日挑战赛# HarmonyOS - 方舟开发框架ArkUI 流光按钮效果