PAT-B-1022 D-ary A + B

Enter two non-negative decimal integers A and B (≤2 30 -1), the output A + B of the D (1 <D≤10) binary number.

Input formats:

A given integer input successively three in a row, B and D.

Output formats:

Output A + D B of the hexadecimal number.

Sample input:

123 456 8

Sample output:

1103
#include <stdio.h>

int main()
{
    int a,b,c,d,ans[31],i=0;
    scanf("%d %d %d",&a,&b,&d);  //输入操作数
    c=a+b;
    do
    {
        ans[i++]=c%d;  //存储余数
        c/=d;    //求得商
    }while(c!=0);
    for(int j=i-1; j>=0; j--)  //逆向取余
        printf("%d",ans[j]);
    return 0;
}

operation result:

Published 462 original articles · won praise 55 · views 320 000 +

Guess you like

Origin blog.csdn.net/LY_624/article/details/88806046