当前位置:网站首页>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;
}
边栏推荐
- The code generator has deoptimised the styling of xx/typescript.js as it exceeds the max of 500kb
- 抖音__ac_signature
- All expansion and collapse of a-tree
- 第一讲:蛇形矩阵
- Un article traite de la microstructure et des instructions de la classe
- Global and Chinese market of diesel fire pump 2022-2028: Research Report on technology, participants, trends, market size and share
- How can easycvr cluster deployment solve the massive video access and concurrency requirements in the project?
- Global and Chinese market of water treatment technology 2022-2028: Research Report on technology, participants, trends, market size and share
- Three.JS VR看房
- 513. Find the value in the lower left corner of the tree
猜你喜欢

Three. JS VR house viewing

Editor extensions in unity

Starting from 1.5, build a micro Service Framework -- log tracking traceid

一文搞定JVM的内存结构

一文搞定class的微观结构和指令

Paddle Serving v0.9.0 重磅发布多机多卡分布式推理框架

Spectrum analysis of ADC sampling sequence based on stm32

VOT Toolkit环境配置与使用

东南亚电商指南,卖家如何布局东南亚市场?

openresty ngx_ Lua request response
随机推荐
I closed the open source project alinesno cloud service
Getting started stm32--gpio (running lantern) (nanny level)
How can easycvr cluster deployment solve the massive video access and concurrency requirements in the project?
Distributed solution selection
Element positioning of Web Automation
Overview of Fourier analysis
TypeError: this. getOptions is not a function
All expansion and collapse of a-tree
audiopolicy
Element operation and element waiting in Web Automation
3 find the greatest common divisor and the least common multiple
openresty ngx_lua正则表达式
[screen recording] how to record in the OBS area
媒体查询:引入资源
第一讲:蛇形矩阵
Spectrum analysis of ADC sampling sequence based on stm32
第十七周作业
Openresty ngx Lua regular expression
Boring boring
Nacos 的安装与服务的注册