当前位置:网站首页>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;
}
边栏推荐
- MoCo: Momentum Contrast for Unsupervised Visual Representation Learning
- Why does the C# compiler allow an explicit cast between IEnumerable&lt; T&gt; and TAlmostAnything?
- Global and Chinese markets for reciprocating seal compressors 2022-2028: Research Report on technology, participants, trends, market size and share
- Registration and skills of hoisting machinery command examination in 2022
- 透彻理解JVM类加载子系统
- Metaverse ape received $3.5 million in seed round financing from negentropy capital
- 一文搞定垃圾回收器
- fibonacci search
- Google Maps case
- Paddle Serving v0.9.0 重磅发布多机多卡分布式推理框架
猜你喜欢
实现反向代理客户端IP透传
Unity Max and min constraint adjustment
Ultrasonic sensor flash | LEGO eV3 Teaching
利用LNMP实现wordpress站点搭建
Nangou Gili hard Kai font TTF Download with installation tutorial
audiopolicy
Simple and beautiful method of PPT color matching
Spectrum analysis of ADC sampling sequence based on stm32
一文搞定垃圾回收器
SPSS analysis of employment problems of college graduates
随机推荐
audiopolicy
Starting from 1.5, build a micro Service Framework -- log tracking traceid
南京:全面启用商品房买卖电子合同
Marginal probability and conditional probability
VOT Toolkit环境配置与使用
Registration and skills of hoisting machinery command examination in 2022
Why does the C# compiler allow an explicit cast between IEnumerable&lt; T&gt; and TAlmostAnything?
Distributed solution selection
第一讲:蛇形矩阵
关于MySQL的30条优化技巧,超实用
Three.js-01 入门
CJ mccullem autograph: to dear Portland
Thinkphp5.1 cross domain problem solving
The difference between MVVM and MVC
一文搞定JVM常见工具和优化策略
Hcip day 12 (BGP black hole, anti ring, configuration)
Openresty ngx Lua regular expression
Solve the problem of "no input file specified" when ThinkPHP starts
Exponential weighted average and its deviation elimination
Composition of interface