题意是将十进制数转换成二进制数。
从网上找到的十进制转 k 进制的做法,代码如下:
1 #include2 using namespace std; 3 char a[]={ '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; 4 void conv(int n,int k)//k 为进制 5 { 6 int r; 7 r = n%k; 8 n = n/k; 9 if(n) conv(n,k); 10 printf("%c",a[r]); 11 } 12 int main() 13 { 14 int n,k; 15 while(~scanf("%d",&n)) 16 { 17 conv(n,k); 18 puts(""); 19 } 20 return 0; 21 }
感谢这篇文章的作者:https://blog.csdn.net/sdz20172133/article/details/79748303