輸入一個十進制非負整數(shù),將其轉(zhuǎn)換成對應的 R (2 <= R <= 9) 進制數(shù),并輸出。 Input
第一行輸入需要轉(zhuǎn)換的十進制非負整數(shù); 第二行輸入 R。 Output
輸出轉(zhuǎn)換所得的 R 進制數(shù)。 Example Input
1279 8
Example Output
2377
n=0的時候單獨判斷一下
#include <stdio.h>#include <string.h>int main(){ int n,r,top=-1; int a[100000]; scanf("%d%d",&n,&r); if(n==0) printf("0"); while(n) { a[++top]=n%r; n/=r; } int i; for(i=top;i>=0;i--) { printf("%d",a[i]); } return 0;}新聞熱點
疑難解答