又一版 A+B

又一版 A+B

輸入兩個不超過整型定義的非負10進制整數A和B(<=231-1),輸出A+B的m (1 < m <10)進制數。

Input

輸入格式:測試輸入包含若干測試用例。每個測試用例佔一行,給出m和A,B的值。 當m爲0時輸入結束。

Output

輸出格式:每個測試用例的輸出佔一行,輸出A+B的m進制數。

Sample Input

     8 1300 48 
     2 1 7
     0

Sample Output

     2504  
     1000                  
#include <stdio.h>
void chance(int x,int n)
{
    int y;
    if(x)
    {
        chance(x / n, n);
        y = x % n;
        printf("%d", y);
    }
}

int main(void)
{
    int m;
    while(scanf("%d", &m) == 1 && m != 0)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        chance(a + b, m);
        printf("\n");
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章