输入两个非负10进制整数A和B(<=2^30^-1),输出A+B的D (1 < D <= 10)进制数。
输入格式:
输入在一行中依次给出3个整数A、B和D。
输出格式:
输出A+B的D进制数。
输入样例:
123 456 8
输出样例:
1103
建议大家利用栈辅助输出,尽量少用数组反转输出,毕竟学过的知识总要用的 >.<
#include <iostream>
using namespace std;
int main(){
int a,b,d;
cin>>a>>b>>d;
int num[100],top=-1;
int c=a+b;
// cout<<c<<endl;
if(c==0||d==10)
{
cout<<c;
return 0;
}
while(c)
{
num[++top]=c%d;
c=c/d;
}
while(top>-1)
{
cout<<num[top--];
}
return 0;
}