当前位置:网站首页>C language entry combat (13): decimal number to binary
C language entry combat (13): decimal number to binary
2022-08-02 06:19:00 【liber】
这是《C语言入门实战》系列的第13篇.
上一篇:C语言入门实战(12):求自然常数e的值
题目
从键盘输入任意一个正整数(≤255),Convert it to the corresponding8位二进制数,请编程实现.
要求
要求
输入输出格式示例1:
输入:160<回车>
输出:10100000
输入输出格式示例2:
输入:255<回车>
输出:11111111
输入输出格式示例3:
输入:13<回车>
输出:00001101
参考代码
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
//为整型值nAllocate stack address
int n;
scanf("%d", &n);
int a[8] = {
0,0,0,0,0,0,0,0};
int idx = 7;
while(n>0 && idx>=0) {
a[idx] = n%2;
n /= 2;
idx--;
}
int i;
for(i=0;i<8;i++) {
printf("%d", a[i]);
}
return 0;
}
代码复盘
Familiarize yourself with the conversion method between decimal and binary through this question.
边栏推荐
- 公司不重视软件测试,新来的阿里P8给我们撰写了测试用例编写规范
- go项目的打包部署
- Introduction and use of apifox (1).
- 复盘:图像饱和度计算公式和图像信噪(PSNR)比计算公式
- 网安学习-内网渗透4
- C语言小游戏——扫雷小游戏
- The original question on the two sides of the automatic test of the byte beating (arranged according to the recording) is real and effective 26
- MySQL 5.7 upgrade to 8.0 detailed process
- MySQL 8.0.28 version installation and configuration method graphic tutorial
- 构造方法、成员变量、局部变量
猜你喜欢

How much does a test environment cost? Start with cost and efficiency

How Navicat Connects to MySQL

一线大厂软件测试流程(思维导图)详解

自动化运维工具——ansible、概述、安装、模块介绍

ATM系统

Packaging and deployment of go projects

JUC(一)- JUC学习概览 - 对JUC有一个整体的认识

Go语言之interface详解

MySql copies data from one table to another table

MySQL 8.0.29 set and modify the default password
随机推荐
Brush LeetCode topic series - 10. Regular expression match
nacos注册中心
apifox介绍及使用(1)。
Use the browser's local storage to realize the function of remembering the user name
C语言入门实战(13):十进制数转二进制
Mysql common commands
面试测试工程师一般会问什么?测试主管告诉你
服务器的单机防御与集群防御
165.比较版本号
Go language study notes - grpc serverclient protobuf Go language from scratch
MySQL implements sorting according to custom (specified order)
Google Chrome(谷歌浏览器)安装使用
Cyber Security Learning - Intranet Penetration 4
[PSQL] 窗口函数、GROUPING运算符
软件测试在职2年跳槽4次,你还在怪老板不给你涨薪?
MySQL multi-table association one-to-many query to get the latest data
How Navicat Connects to MySQL
C语言小游戏——扫雷小游戏
去字节跳动自动化测试二面原题(根据录音整理)真实有效 26
TikTok平台的两种账户有什么区别?