当前位置:网站首页>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;
}边栏推荐
- AHA C language Chapter 7 you can do more with it (talks 27-28)
- LeetCode-1757. Recyclable and low-fat products_ SQL
- 英集芯IP5566带TYPE-C口3A充放快充移动电源5w无线充二合一方案SOC
- Shutdown shutdown command
- Qimen dunjia assistant decision software
- Advanced Mathematics (Seventh Edition) Tongji University exercises 1-8 personal solutions
- What is the magic of digital collections? Which reliable teams are currently developing
- MySQL面试真题(二十五)——常见的分组比较场景
- [graduation season u; advanced technology Er] farewell to the confused self in the past two years. Regroup, junior I'm coming
- [opencv450] image subtraction, binarization, threshold segmentation
猜你喜欢

MySQL面试真题(二十六)——滴滴2020年笔试题

抽奖 ddd 代码

Wechat applet: production and generation of love guarantee

Wechat applet: elderly blessing short video

MySQL面试真题(二十一)——金融-贷款逾期

Wechat applet: wechat can also send flash photos to create wechat applet source code download and customize flash time

visdom的使用

Shifu, the open source development platform of the Internet of things, is open for internal testing! Release of the first version of technical documents

Real MySQL interview question (XXVIII) -- case - Analysis of indicators of communication operators

MySQL面试真题(二十三)——拼多多-球赛分析
随机推荐
英文字母pc是什么意思,互联网的pc指的是什么
Differences between fs4059a and fs5080e charging chips
opencv显示图像
PAT 乙等 1025 反转链表
The performance of nonstandard sprintf code in different platforms
Mobile phone wireless charging dual coil 15W scheme SOC IC ip6809
Ansible 使用普通用户管理被控端
104. simple chat room 7: use socket to transfer objects
How can digital collections empower economic entities?
Real MySQL interview question (30) -- shell real estate order analysis
ssm项目搭建
Leetcode 797: all possible paths
mysql字符集
高等数学(第七版)同济大学 习题1-7 个人解答
Is there a real part-time job online? How do college students find part-time jobs in summer?
MDM数据清洗功能开发说明
1010 Radix
技术开发团队视角看到的数字藏品机遇与挑战
Shutdown shutdown command
The road of architects starts from "storage selection"