1022. A+B in D-base (20)

[Thinking] Divide R and count down the remainder to achieve base conversion, and use the do...while loop to avoid the need to separately judge the value of zero.

#include <stdio.h>
#include <stdlib.h>

intmain ()
{
    int A,B,D,sum,a[100];
    scanf("%d%d%d",&A,&B,&D);
    sum = A+B;
    int i=0;
    do{
        a[i++] = sum%D;
        sum = sum/D;
    }while(sum!=0);
    for(int j=i-1;j>=0;j--){
        printf("%d",a[j]);
    }
    return 0;
}

Guess you like

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