30 = 2 * 15 + 0
15 = 2 * 7 + 1
7 = 2 * 3 +1
3 = 2 * 1 +1
1 = 2 * 0 + 1
30 ⇒ 11110
#include<stdio.h>
int main( )
{
int input,s[1000]={0};
int index = 0;
while(scanf("%d",&input) != EOF) {
index=0; // index 重置
while(input!=1) {
// 使用陣列存 餘數
s[index]=input%2;
input/=2;
index++;
}
s[index] = 1;
// 逆輸出陣列
for(int j=index;j>=0; j--) {
printf("%d",s[j]);
}
printf("\\n");
}
return 0;
}