1022. D进制的A+B

题目在这里


要注意0的情况,如果不写判断是输不出来的。

#include <iostream>
using namespace std;

int main()
{
	int a, b, d;
	cin >> a >> b >> d;
	int num = a + b;
	int c[1001];
	int k = 0;
	if(num == 0) {
		cout << "0";
		return 0;
	} 
	while(num) {
		c[k++] = num % d;
		num = num / d;
	}
	for(int i = k - 1; i >= 0; i--) {
		cout << c[i];
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_39227338/article/details/80000806