PAT 1022. D進位的A+B (20)

來源:互聯網
上載者:User

標籤:pat   code   blog   turn   log   進位   div   整數   pre   

輸入兩個非負10進位整數A和B(<=230-1),輸出A+B的D (1 < D <= 10)進位數。

輸入格式:

輸入在一行中依次給出3個整數A、B和D。

輸出格式:

輸出A+B的D進位數。

輸入範例:

123 456 8

輸出範例:

1103

要特別注意a+b=0的情況
 1 #include<stdio.h> 2 #include<string.h> 3 #include<math.h> 4 #include<stdlib.h> 5 int main(){ 6     long a,b; 7     int d; 8     scanf("%ld %ld",&a,&b); 9     scanf("%d",&d);10     if(a+b==0){11         printf("0");12         return 0;13     }14     long sum = a+b;15     int c[100];16     int i=0;17     while(sum!=0){18         c[i++] = sum%d;19         sum = sum/d;20     }21     int n = i-1;22     for(i=n;i>=0;i--){23         printf("%d",c[i]);24     }25     26     27      28 }

 

PAT 1022. D進位的A+B (20)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.