标签:
1 #include <stdio.h> 2 #include <string.h> 3 #include <cmath> 4 int a[32]; 5 int main() 6 { 7 int N, R, k; 8 while(~scanf("%d%d", &N, &R)) 9 { 10 k = 0; 11 //memset(a, 0, sizeof(a)); 12 if(R > 16 || R < 2 || R == 10) 13 continue; 14 if(N < 0) printf("-"); 15 while(N) 16 { 17 a[k++] = abs(N%R); 18 N = abs(N/R); 19 } 20 if(R < 10) 21 { 22 for(int j = k-1; j >= 0; j--) 23 printf("%d", a[j]); 24 } 25 else 26 { 27 for(int j = k - 1; j >= 0; j--) 28 printf("%X",a[j]);//以十六进制输出 29 } 30 printf("\n"); 31 } 32 return 0; 33 }
标签:
原文地址:http://www.cnblogs.com/digulove/p/4721682.html