当前位置:网站首页>C Primer Plus Chapter 9 question 10 binary conversion
C Primer Plus Chapter 9 question 10 binary conversion
2022-07-05 23:00:00 【multydoffer】
Write a to_base_n() Accept functions in two 2-10 Parameters in range , Then take the second 1 Hexadecimal print specified in parameter No 2 Number of parameters . for example ,to_base_n(129,8) The result is 201, That is to say 129 The octal number of . Test the function in a complete program .
Here is the code :
#include <stdio.h>
void to_base_n(int n, int x);
int main(void)
{
int n, x;
printf("Enter a number and the base for the form of prints.\n");
printf("Now enter the number in the demical system: ");
scanf("%d", &x);
printf("Enter the base of it(2-10): ");
scanf("%d", &n);
while(n < 2 && n > 10)
{
printf("Enter the base(2-10): ");
scanf("%d", &n);
}
to_base_n(n, x);
return 0;
}
void to_base_n(int n, int x)
{
if(x < 0)
{
x *= -1;
printf("-");
}
if(x > 0)
{
to_base_n(n, x / n);
printf("%d", x % n);
}
return;
}
边栏推荐
- How can easycvr cluster deployment solve the massive video access and concurrency requirements in the project?
- Openresty ngx Lua regular expression
- 基于STM32的ADC采样序列频谱分析
- Registration of Electrical Engineering (elementary) examination in 2022 and the latest analysis of Electrical Engineering (elementary)
- Thinkphp5.1 cross domain problem solving
- The method and principle of viewing the last modification time of the web page
- 傅里叶分析概述
- Vcomp110.dll download -vcomp110 What if DLL is lost
- Arduino 测量交流电流
- The code generator has deoptimised the styling of xx/typescript. js as it exceeds the max of 500kb
猜你喜欢
视频标准二三事
透彻理解JVM类加载子系统
Metaverse ape received $3.5 million in seed round financing from negentropy capital
Three.js-01 入门
终于搞懂什么是动态规划的
Paddle Serving v0.9.0 重磅发布多机多卡分布式推理框架
The method and principle of viewing the last modification time of the web page
Business introduction of Zhengda international futures company
Overview of Fourier analysis
分布式解决方案之TCC
随机推荐
[untitled]
抖音__ac_signature
Leetcode daily question 1189 The maximum number of "balloons" simple simulation questions~
Element operation and element waiting in Web Automation
第十七周作业
Why does the C# compiler allow an explicit cast between IEnumerable&lt; T&gt; and TAlmostAnything?
Nacos 的安装与服务的注册
2022 registration examination for safety management personnel of hazardous chemical business units and simulated reexamination examination for safety management personnel of hazardous chemical busines
Double pointeur de liste liée (pointeur rapide et lent, pointeur séquentiel, pointeur de tête et de queue)
a-tree 树的全部展开和收起
[speech processing] speech signal denoising and denoising based on MATLAB low-pass filter [including Matlab source code 1709]
Ultrasonic sensor flash | LEGO eV3 Teaching
如何快速理解复杂业务,系统思考问题?
第一讲:蛇形矩阵
关于MySQL的30条优化技巧,超实用
Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题
Global and Chinese market of water treatment technology 2022-2028: Research Report on technology, participants, trends, market size and share
傅里叶分析概述
Hcip day 12 (BGP black hole, anti ring, configuration)
实现反向代理客户端IP透传