题目来源:码蹄集
https://matiji.net/exam/brushquestion/298/778/B3FCFEC101BD05189BB74D522E019504
参考程序:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,i,k=0,ai;
scanf("%d",&n);
if(n==0)
{
printf("0");
return 0;
}
ai = n;
while (n > 0){
n = n/2;
k += 1;
}
int a[k];
for (i = 0; i<= k;i++){
if (ai < 0) break;
else {
a[i] = ai %2;
ai /=2;
}
}
for (i=k-1; i>=0;i--){
printf("%d",a[i]);
}
return 0;
}