1022. A+B in D base

topic here


Pay attention to the case of 0, if you don't write the judgment, you can't output it.

#include <iostream>
using namespace std;

intmain()
{
	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;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325785697&siteId=291194637