当前位置:网站首页>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;
}
边栏推荐
- Expectation, variance and covariance
- 媒体查询:引入资源
- Unity Max and min constraint adjustment
- Double pointeur de liste liée (pointeur rapide et lent, pointeur séquentiel, pointeur de tête et de queue)
- Hcip day 12 (BGP black hole, anti ring, configuration)
- Lesson 1: serpentine matrix
- 实现反向代理客户端IP透传
- Thinkphp5.1 cross domain problem solving
- Three. JS VR house viewing
- 终于搞懂什么是动态规划的
猜你喜欢
Three.JS VR看房
一文搞定垃圾回收器
Finally understand what dynamic planning is
2022 G3 boiler water treatment simulation examination and G3 boiler water treatment simulation examination question bank
openresty ngx_ Lua request response
利用LNMP实现wordpress站点搭建
第一讲:蛇形矩阵
Three. Js-01 getting started
All expansion and collapse of a-tree
[speech processing] speech signal denoising and denoising based on Matlab GUI low-pass filter [including Matlab source code 1708]
随机推荐
[secretly kill little buddy pytorch20 days] - [Day2] - [example of picture data modeling process]
Why does the C# compiler allow an explicit cast between IEnumerable&lt; T&gt; and TAlmostAnything?
How can easycvr cluster deployment solve the massive video access and concurrency requirements in the project?
Finally understand what dynamic planning is
Paddle Serving v0.9.0 重磅发布多机多卡分布式推理框架
2022.02.13 - SX10-30. Home raiding II
3 find the greatest common divisor and the least common multiple
APK加固技术的演变,APK加固技术和不足之处
Simple and beautiful method of PPT color matching
Getting started stm32--gpio (running lantern) (nanny level)
[speech processing] speech signal denoising based on Matlab GUI Hanning window fir notch filter [including Matlab source code 1711]
【Note17】PECI(Platform Environment Control Interface)
鏈錶之雙指針(快慢指針,先後指針,首尾指針)
从 1.5 开始搭建一个微服务框架——日志追踪 traceId
Ultrasonic sensor flash | LEGO eV3 Teaching
关于MySQL的30条优化技巧,超实用
openresty ngx_ Lua request response
记录几个常见问题(202207)
利用LNMP实现wordpress站点搭建
LeetCode102. Sequence traversal of binary tree (output by layer and unified output)