输入两个非负 10 进制整数 A 和 B (≤230−1),输出 A+B 的 D (1<D≤10)进制数。
输入格式:
输入在一行中依次给出 3 个整数 A、B 和 D。
输出格式:
输出 A+B 的 D 进制数。
输入样例:
123 456 8
输出样例:
1103
代码:
#include <stdio.h>
int main(int argc, char const *argv[]){
int a, b, d;
scanf("%d %d %d", &a, &b, &d);
a += b;
int result[32] = {0};
int temp;
temp = 0;
if( a+b==0 )
printf("0");
while( a!=0 ){
result[temp] = a % d;
a /= d;
temp++;
}
for(; temp>0; temp--)
printf("%d", result[temp-1]);
printf("\n");
return 0;
}
由于我也是初学者,只是想分享一下自己学习的过程,所以有不好的地方还请大家指点,不胜感激!