当前位置:网站首页>PAT 乙等 1022 D进制的A+B
PAT 乙等 1022 D进制的A+B
2022-06-23 04:11:00 【章鱼bro】
1022. D进制的A+B (20)
输入两个非负10进制整数A和B(<=230-1),输出A+B的D (1 < D <= 10)进制数。
输入格式:
输入在一行中依次给出3个整数A、B和D。
输出格式:
输出A+B的D进制数。
输入样例:123 456 8输出样例:
1103
思路:对A+B之和采用除D取余法,在和未被除完之前记录每一次除法的余数,最后倒序输出。类似十进制转换二进制的除二取余法。
一、起始变量
1.A、B两个10进制整数
2.D要转换的位制
3.a【31】,存储余数的的数组,因为最多为转换为2进制的时候有31位
二、运算
1.读入A和B,并计算其和
2.进行除D取余,直到商为0
3.倒序输出余数
三、代码
#include "stdio.h"
#include "math.h"
int main()
{
int A,B,D;
scanf("%d %d %d", &A, &B, &D);
int left = A + B;//计算两数之和,left代表每次除法之后的商
int a[31] = {0};
//使用类似十进制转二进制的方法,即除D取余,a数组用来存储余数,最后倒序输出,因为最多是转二进制 ,故31位
int i = 0;
do
{
a[i] = left % D;//保存余数
left /= D;
i++;
}while(left != 0);
for(i = i - 1 ; i >= 0; i--)
{
printf("%d",a[i]);
}
return 0;
}边栏推荐
- Ansible 使用普通用户管理被控端
- 英集芯推出4串锂电池100W移动电源升降压方案SoC芯片IP5389
- Visdom draws multiple dynamic loss curves
- How to move the software downloaded from win11 app store to the desktop
- QT QWidget nesting relative position acquisition (QT drawing nesting)
- Raspberry pie assert preliminary exercise
- C primer plus学习笔记 —— 2、常量与格式化IO(输入/输出)
- How can digital collections empower economic entities?
- MDM data cleaning function development description
- Ip6809 three coil 15W wireless charging transmitter scheme IC British chip
猜你喜欢

visdom的使用

Yingjixin ip6806 wireless charging scheme 5W Qi certified peripheral simplified 14 devices

What benefits have digital collections enabled the real industry to release?

Wechat applet: Star Trek spaceship ticket production and generation

Wechat applet: unfashionable love talk

STC 32 Bit 8051 Single Chip Computer Development Example Tutorial one development environment

Fs2119a Synchronous Boost IC output 3.3V and fs2119b Synchronous Boost IC output 5V

电脑开机显示器黑屏是什么原因,电脑显示器黑屏怎么办

Software design and Development Notes 2: serial port debugging tool based on QT design

STC 32-bit 8051 MCU development example tutorial I development environment construction
随机推荐
Genetic engineering of AI art? Use # artbreeder to change any shape of the image
英文字母pc是什么意思,互联网的pc指的是什么
Win11应用商店下载的软件怎么移到桌面
104. simple chat room 7: use socket to transfer objects
Oracle异常
AHA C language Chapter 8 game time is up (lesson 29)
@jsonfield annotation in fastjson
[opencv450] inter frame difference method
What does the English letter PC mean? What does the Internet PC mean
1010 Radix
Design and implementation of spark offline development framework
Export PDF with watermark
英集芯推出4串锂电池100W移动电源升降压方案SoC芯片IP5389
Opencv display image
Oracle exception
MySQL面试真题(二十二)——表连接后的条件筛选及分组筛选
啊哈C语言 第8章 游戏时间到了(第29讲)
Leetcode 797: all possible paths
How much disk IO will actually occur for a byte of the read file?
ssm项目搭建