思路:
这是一个进制转换的题,首先确认a+b的值还是在int范围内的,所以只需要把d转换成数组。
需要注意的一点就是0+0的情况。
代码:
#include<iostream>
using namespace std;
int num[100] = { 0 };
int a, b, c, d;
int main()
{
int count = 0;
cin >> a >> b >> c;
d = a + b;
if (d == 0)
{
cout << 0;
return 0;
}
while (d > 0)
{
num[count] = d%c;
d = d / c;
count++;
}
while (count > 0)
{
count--;
cout << num[count];
}
//while (1)
//{
//}
return 0;
}